I have a problem about drawing a seaborn bar plot in terms of this dataframe shown below
I created df_total shown below
df_total = df[['Confirmed','Recovered','Deaths']].sum()
df_total = df_total.reset_index()
Here is my dataframe named for 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?
Use DataFrame.rename_axis
for set index name and then add parameter name
in Series.reset_index
:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.