How to create a bar chart based on the presented data frame?

Data Frame

I am trying to produce a bar chart for the data frame above and I am having issues doing so. My code for this data frame is:

high_pay[['Sport', 'Name', 'Year', 'earnings ($ million)']] \
    .sort_values('earnings ($ million)', ascending=False) \
    .drop_duplicates('Sport', keep='first')

What would be the appropriate way to put this information in a bar chart where Sport is on the x axis and earnings ($ million) is on the y axis?

>Solution :

Yes you can do that with something like the following.

import matplotlib.pyplot as plt

high_pay = pd.DataFrame({'Sport': ['Boxing','Soccer','Golf','Tennis','MMA','NFL','NBA','Auto Racing','Baseball','Hockey','Cycling','American Football / Baseball'],
                   'Earnings ($ million)': [300,127,115,106.3,99,89.5,89,80,35,29.8,28,22.5]
                   })


plt.bar(high_pay["Sport"].values, high_pay['Earnings ($ million)'].values)
#format labels on x-axis
plt.xticks(rotation=45, ha='right')
plt.show()

enter image description here

Leave a Reply