Nastya
Nastya

Reputation: 81

Creating bar plot using dataframe with multi-indexing

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

Upvotes: 2

Views: 73

Answers (2)

jezrael
jezrael

Reputation: 862521

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

import matplotlib.pyplot as plt

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

plt.show()

graph

Upvotes: 2

MMF
MMF

Reputation: 5929

Try the following :

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

Upvotes: 0

Related Questions