简体   繁体   English

使用Pandas Value_Counts和matplotlib

[英]Using Pandas Value_Counts and matplotlib

I have used Pandas's value_counts function to provide counts of unique values: 我使用Pandas的value_counts函数来提供唯一值的计数:

CountStatus = pd.value_counts(df['scstatus'].values, sort=True)

Output:
200    133809
304      7217
404      2176
302       740
500       159
403         4
301         1
dtype: int64

I now want to plot these values using matplotlib ie "plt.barh(CountStatus)", however I keep getting the error: ValueError: incompatible sizes: argument 'width' must be length 7 or scalar. 我现在想用matplotlib绘制这些值,即“plt.barh(CountStatus)”,但是我不断收到错误:ValueError:不兼容的大小:参数'width'必须是长度7或标量。

I'm guessing this may have something to do with the left hand column being an index column. 我猜这可能与左手列是索引列有关。 Is there a way around this to obtain a horizontal bar chart? 有没有办法获得水平条形图? Do I need to convert it or specify something else in the function? 我是否需要转换它或在函数中指定其他内容?

Thanks 谢谢

I think you can use barh : 我想你可以用barh

CountStatus.plot.barh()

Sample: 样品:

CountStatus = pd.value_counts(df['scstatus'].values, sort=True)
print CountStatus
AAC    8
AA     7
ABB    4
dtype: int64

CountStatus.plot.barh()

图形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM