Reputation: 186
I have multi-indexed dataframe with single column. I want to plot stacked bar graph based on that dataframe. The data is as follows:
df= pd.DataFrame(index=pd.MultiIndex([[1,2,3],['open','closed']],[[0,0,1,1,2,2],[0,1,0,1,0,1]]))
df['id']=[23,6,12,4,31,16]
df
id
state
1 closed 23
open 6
2 closed 12
open 4
3 closed 31
open 16
Upvotes: 4
Views: 117
Reputation: 36545
You need to unstack
your dataframe:
%matplotlib inline
df.unstack().plot(kind='bar', stacked=True)
Upvotes: 6