PANDAS 条形图为空且缺少 x 和 y 标签

问题描述 投票:0回答:1

所以我有以下代码:

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()

以及以下 csv 文件(我不知道如何附加文件,所以我将用代码编写其内容):

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

如标题所述,条形图缺少 x 和 y 标签及其内容。有人可以建议修复吗?

我试图足够有趣地阅读堆栈溢出,并且我读了一篇建议做相当于

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

但是,当我尝试这样做时,出现属性错误。

python pandas
1个回答
0
投票

评论此行后尝试 plt.title(“美国最喜欢的苏打水”)

© www.soinside.com 2019 - 2024. All rights reserved.