[英]How can I plot the dataframe in seaborn bar?
I have a problem about drawing a seaborn bar plot in terms of this dataframe shown below我有一个关于根据下面显示的数据框绘制 seaborn 条形图的问题
I created df_total shown below我创建了如下所示的 df_total
df_total = df[['Confirmed','Recovered','Deaths']].sum()
df_total = df_total.reset_index()
Here is my dataframe named for df_total这是我以 df_total 命名的数据框
index 0
0 Confirmed 145193
1 Recovered 70251
2 Deaths 5404
Plot阴谋
sns.barplot(x = "", y = ""
data = df_total )
Which x and y values should be determined to draw bar plot?应该确定哪些 x 和 y 值来绘制条形图?
Use DataFrame.rename_axis
for set index name and then add parameter name
in Series.reset_index
:使用
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 )
Your solution should be changed:您的解决方案应该改变:
sns.barplot(x = "index", y = 0, data = df_total)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.