[英]How to plot 1-row dataframe as a barplot in seaborn?
I don't understand, what it wants from dataframe to be plotted.我不明白,它想要从数据框中绘制什么。 I have a dataframe
我有一个数据框
and trying to plot it.并试图绘制它。 The goal is to have one bar per colum.
目标是每列有一个酒吧。 But I can't.
但我不能。
I tried various combinations of this:我尝试了各种组合:
#df = df.transpose()
sns.barplot(y=df.index.values, x=df.values, order=df.index)
Try to change this wide format to long format using melt
function in pandas.尝试使用这种宽幅更改为长格式
melt
功能大熊猫。
long_df = pd.melt(df)
sns.barplot(y = long_df.variable, x = long_df.value)
Plot using seaborn.barplot使用 seaborn.barplot 绘图
import pandas as pd
import seaborn as sns
sales = {'Tony': 103,
'Sally': 202,
'Randy': 380,
'Ellen': 101,
'Fred': 82
}
#making dict to 1 row DataFrame
df = pd.DataFrame(sales, index=[0])
#flattening the values to be compliant with
#barplot method of seaborn and columns of dataframe
values = df.values.flatten()
sns.barplot(x = df.columns,y=values)
The only problem with your data is just you need to flatten it to make it compatible and use the above arguments of barplot您的数据唯一的问题是您需要将其展平以使其兼容并使用 barplot 的上述参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.