Python 使用Pandas Value_计数和matplotlib
我已使用Pandas的value_counts函数提供唯一值的计数:Python 使用Pandas Value_计数和matplotlib,python,pandas,matplotlib,plot,Python,Pandas,Matplotlib,Plot,我已使用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 现在,我想使用matplotlib(即“plt.barh(C
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
现在,我想使用matplotlib(即“plt.barh(CountStatus)”)来绘制这些值,但是我不断得到错误:ValueError:大小不兼容:参数“width”的长度必须为7或标量
我猜这可能与左边的列是索引列有关。有没有办法获得水平条形图?我需要转换它还是在函数中指定其他内容
谢谢我想你可以使用:
样本:
CountStatus = pd.value_counts(df['scstatus'].values, sort=True)
print CountStatus
AAC 8
AA 7
ABB 4
dtype: int64
CountStatus.plot.barh()
哇..我是个大傻瓜哈哈。谢谢如何使用这种方式排序和添加标签?如何添加图例?
CountStatus = pd.value_counts(df['scstatus'].values, sort=True)
print CountStatus
AAC 8
AA 7
ABB 4
dtype: int64
CountStatus.plot.barh()