分类数据我有一个分类数据的数据帧:绘制与大熊猫和matplotlib
colour direction
1 red up
2 blue up
3 green down
4 red left
5 red right
6 yellow down
7 blue down
我想要生成一些图表,如基于类别饼图和柱状图。有没有可能创建虚拟数字变量?像
df.plot(kind='hist')
分类数据我有一个分类数据的数据帧:绘制与大熊猫和matplotlib
colour direction
1 red up
2 blue up
3 green down
4 red left
5 red right
6 yellow down
7 blue down
我想要生成一些图表,如基于类别饼图和柱状图。有没有可能创建虚拟数字变量?像
df.plot(kind='hist')
这样的:
df.groupby('colour').size().plot(kind='bar')
您可能会发现从statsmodels有用mosaic
情节。这也可以为差异提供统计突出显示。
from statsmodels.graphics.mosaicplot import mosaic
plt.rcParams['font.size'] = 16.0
mosaic(df, ['direction', 'colour']);
但0大小的蜂窝状的提防 - 它们会导致与标签的问题。
见this answer的细节
暗示'DF [ “颜色”。value_counts()。图(KIND = '酒吧')'共同替代 – openwonk
是否可以指定x标签的顺序? –