How to build a lot of indexed dataframe in python using python?

I have a multi-indexed dataframe with one column. I want to build a glass split chart based on this frame. 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
+4
source share
1 answer

You need unstackyour data framework:

%matplotlib inline
df.unstack().plot(kind='bar', stacked=True)

enter image description here

+6
source

Source: https://habr.com/ru/post/1606203/


All Articles