In [23]:
from bokeh.io import output_notebook, show
from bokeh.charts import Bar
output_notebook()


Loading BokehJS ...

In [24]:
import pandas as pd
from numpy.random import randint

In [25]:
index = pd.Index([1,2,3,4,5], label='period')
columns = pd.Index(['A', 'B', 'C'], label='categories')
values = randint(10, 100, 15).reshape(5, 3)
values.sort(axis=0)
df = pd.DataFrame(values, index, columns)
original_df = df.copy()

In [26]:
original_df


Out[26]:
A B C
1 15 12 23
2 26 12 31
3 45 48 66
4 53 48 75
5 82 64 89

In [27]:
list(randint(10, 100, 15))


Out[27]:
[48, 36, 84, 29, 92, 70, 46, 26, 23, 15, 14, 60, 87, 26, 66]

In [43]:
data = {
    'period': [1, 2, 3, 4, 5] * 3,
    'cat': ['A' ,'B', 'C'] * 5,
    'value': list(randint(10, 100, 15))
}
long_df = pd.DataFrame(data)
long_df = long_df.sort_values(by='cat')
long_df.head()


Out[43]:
cat period value
0 A 1 33
3 A 4 46
6 A 2 20
9 A 5 63
12 A 3 73

In [44]:
show(Bar(long_df, label='period', values='value', stack='cat', legend=True))


Out[44]:

<Bokeh Notebook handle for In[44]>


In [ ]: