[英]Plot with seaborn after groupby command in pandas
我已經使用熊貓對列表進行了分組,並且試圖用seaborn繪制下面的表格:
B
A
bar 3
foo 5
代碼sns.countplot(x='A', data=df)
不起作用(ValueError: Could not interpret input 'A')
。
我可以只使用df.plot(kind='bar')
但我想知道是否可以用seaborn進行繪圖。
在這種情況下,我認為您可能缺少重置索引,因此可以使用該索引。
sns.countplot(x='A', data=df.reset_index())
還要檢查用於分組的hue參數,這可能會使您的分組不再必要
import seaborn as sns
df = pd.DataFrame( [['A', 'B', 'A'], [1,1,1], [4,5,4]], index=['g', 'x', 'y']).T
sns.countplot(data=df, x='y', hue='g')
嘗試:
sns.countplot(x='A', data=df.reset_index())
似乎A列是一個索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.