Creating bar plot using dataframe with multi-indexing

70 views Asked by At

I have the following dataFrame:

         Score
one  A     8
     B    19
     D    29
two  C    18
     A    10
     B     4
     D     2
six  C     4
     A     4
     B     4

And I wish to create one bar plot where X axis values are "one", "two" and "six", and each value has 4 bars (A,B,C,D) when the bar height determined by the score column.

Thank you. Nastya

2

There are 2 answers

0
jezrael On BEST ANSWER

You need unstack for reshaping with DataFrame.plot.bar:

import matplotlib.pyplot as plt

df.unstack()['Score'].plot.bar()

plt.show()

graph

1
MMF On

Try the following :

df.unstack(level=1).plot(kind='bar')