PANDAS bar graph is empty and missing x and y labels

  Kiến thức lập trình

So I have the following code:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv(r"data.csv")
pd.set_option("display.max_columns", None)
print(df['soda'].value_counts())
dr = pd.read_csv(r"new_data.csv")

plt.title("Favorite sodas in the U.S.")
axis = dr[['soda','number']].plot(kind='bar',title = 'Favorite sodas of the USA')
axis.set_xlabel("soda", fontsize=12)
axis.set_ylabel("number", fontsize=12)
plt.show()

and the following csv file(I dont know how to attach a file so I’ll write its contents in code):

soda,number
Coca-Cola , 15
Mountain Dew , 10
Dr.Pepper, 7
Pepsi, 6
Root Beer, 5
Spirte, 2
Kool- Aid, 1
Maple Syrup, 1
Starbucks, 1
Ale80ne, 1
Faygo, 1

As stated in the title, the bar graph is missing its x and y label as well as its contents. Can anyone suggest a fix please?

I tried to read stack overflow funnily enough, and I read a post that suggested to do the equivalent of

axis = dr[['soda','number']].plot(kind='bar',ax = 'soda',title = 'Favorite sodas of the USA')

however when I tried to do that I got an Attribute error.

LEAVE A COMMENT