1

I have a dataframe as follow, i want to plot multiple bar by grouping model and scheduler columns. Such as first thee multiple bar belongs to ecaresnet50t three different scheduler and represent mae score. Second three multiple bar represent mae of resnest50d scheduler and so on

         model     scheduler    mae
0   ecaresnet50t      warm      4.518
1   ecaresnet50t      cosine    4.46
2   ecaresnet50t      constant  4.972
3   resnest50d        warm      4.056
4   resnest50d        cosine    4.1
5   resnest50d        constant  5.072
6   resnetrs50        warm      4.164
7   resnetrs50        cosine    4.154
8   resnetrs50        constant  4.644
9   seresnet50        warm      4.202

I tried some thing like this (df.groupby(['model','scheduler'])['mae'].plot.bar()) But its not working

Talha Anwar
  • 2,699
  • 4
  • 23
  • 62
  • 1
    Does this answer your question? [How to create a grouped bar plot](https://stackoverflow.com/questions/47796264/how-to-create-a-grouped-bar-plot) – Mr. T Jan 30 '22 at 13:22

1 Answers1

5

Use a pivot table. They are what you are looking for and alot easier to use in this circumstance than a multiindex groupby.

df_pivot = pd.pivot_table(df, 
                          values="mae", 
                          index="model", 
                          columns="scheduler", 
                          aggfunc=np.mean)

df_pivot.plot.bar()

enter image description here

L. Nelson
  • 179
  • 1
  • 11