0

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.

tdy
  • 36,675
  • 19
  • 86
  • 83
thePandasFriend
  • 115
  • 2
  • 10

1 Answers1

1

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

Pablo C
  • 4,661
  • 2
  • 8
  • 24