我不明白,它想要從數據框中繪制什么。我有一個數據框并試圖繪制它。目標是每列有一個酒吧。但我不能。我嘗試了各種組合:#df = df.transpose()sns.barplot(y=df.index.values, x=df.values, order=df.index)
2 回答

翻過高山走不出你
TA貢獻1875條經驗 獲得超3個贊
嘗試使用melt
pandas 中的函數將此寬格式更改為長格式。
long_df = pd.melt(df) sns.barplot(y = long_df.variable, x = long_df.value)

滄海一幻覺
TA貢獻1824條經驗 獲得超5個贊
使用 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)
您的數據唯一的問題是您需要將其展平以使其兼容并使用 barplot 的上述參數
添加回答
舉報
0/150
提交
取消