How to make a grouped bar chart from a Pandas DataFrame

Question:

How can I use pyplot to plot this dataframe:

          Team   Boys  Girls
0        Sharks    5       5
1         Lions    3       7

data = {'Team': ['Sharks', 'Lions'], 'Boys': [5, 5], 'Girls': [5, 6] }
df = pd.DataFrame(data)

so that I can end up with something like this where there are two bars per team that denote the boys/girls.
enter image description here

It seems to be a messy process with pyplot, so if there is an easier way I am all ears.

Asked By: thePandasFriend

||

Answers:

You can use pandas.DataFrame.plot.bar with rot=0 to rotate the xticks

df.set_index('Team').plot.bar(rot = 0)
plt.show()

plot

Answered By: Pablo C