在《大Pandas》中用groupby命令后与seaborn合作

2024-06-12 22:48:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我用熊猫对一个列表进行了分组,并试图用seaborn绘制下表:

     B  
A           
bar  3  
foo  5  

代码sns.countplot(x='A', data=df)不工作(ValueError: Could not interpret input 'A')。在

我可以用df.plot(kind='bar'),但我想知道是否可以用seaborn来绘制。在


Tags: 代码df列表datafoo绘制notbar
2条回答

尝试:

sns.countplot(x='A', data=df.reset_index())

A列似乎是索引。在

在本例中,我认为您可能缺少一个重置索引,因此可以使用该索引。在

 sns.countplot(x='A', data=df.reset_index())

还要检查用于分组的hue参数,这可能使groupby不必要

^{pr2}$

相关问题 更多 >