python - Difficulty in plotting Pandas Multi-indexed DataFrame or series -


please see image

s = pd.dataframe(combined_df.groupby(['session','age_range', 'gender']).size()) s.head(25)

​                        0 session   age_range gender         evening   0 - 17    female   31022                     male     21754           18 - 24   female   79086                     male     71563                     unknown     75           25 - 29   female   29321                     male     46125                     unknown     44           30 - 34   female   21480                     male     25803                     unknown     33           35 - 44   female   17369                     male     20335                     unknown    121           45 - 54   female    8420                     male     12385                     unknown     24           55+       female    3433                     male      9880                     unknown    212 mid night 0 - 17    female   18456                     male     12185           18 - 24   female   50536                     male     45829                     unknown     62 

this how multi-indexed data frame looks like. trying plot data in such way can compare male , female users of different age groups active during different sessions(say morning, evening, noon , night). example plot male , female users of age group 0-17, 18-24, 25-29... during different sessions have.

note: have tried few examples stack overflow , other websites still unsuccessful in getting need. so, request guys try solving problem , me in finding solution this. have been struggling many days , documentation vague. so, please throw light on problem. ]2

i think can use unstack dataframe.plot.bar:

import matplotlib.pyplot plt df = combined_df.groupby(['session','age_range', 'gender']).size() df.unstack(fill_value=0).plot.bar() plt.show() 

graph


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -