我在根据下面显示的数据帧绘制seaborn条形图时遇到了问题
我创建了如下所示的df_total
df_total = df[['Confirmed','Recovered','Deaths']].sum()
df_total = df_total.reset_index()
这是我以df_total 命名的数据帧
index 0
0 Confirmed 145193
1 Recovered 70251
2 Deaths 5404
绘制
sns.barplot(x = "", y = ""
data = df_total )
绘制条形图时应确定哪些x和y值?
使用DataFrame.rename_axis
设置索引名称,然后在Series.reset_index
:中添加参数name
df_total = df[['Confirmed','Recovered','Deaths']].sum()
df_total = df_total.rename_axis('a').reset_index(name='b')
sns.barplot(x = "a", y = 'b', data = df_total )
您的解决方案应该更改:
sns.barplot(x = "index", y = 0, data = df_total)