[英]Charting gender in IPython notebook using pandas or matplotlib
I have a Pandas dataframe with a Gender column which contains values M or F. I want to chart the count of all M and F as either a bar chart with 2 bars, or a pie chart with 2 wedges. 我有一个带有“性别”列的Pandas数据框,其中包含值M或F。我想将所有M和F的计数绘制为带有2条的条形图或带有2个楔形的饼形图。
So far I've tried hist, but it errors out: 到目前为止,我已经尝试过hist,但是出错了:
data['GENDER'].hist()
TypeError: cannot concatenate 'str' and 'float' objects
Maybe I need to do a groupby? 也许我需要进行分组?
您可能希望此groupby / size获取每个性别的计数,并使用.plot
vs .hist
(这仅对数字数据有意义)。
df.groupby('GENDER').size().plot(kind='bar')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.