使用Pandas Value_Counts和matplotlib

时间:2016-04-21 07:09:46

标签: 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(CountStatus)”,但是我不断收到错误:ValueError:不兼容的大小:参数'width'必须是长度为7或标量。

我猜这可能与左手列是索引列有关。有没有办法获得水平条形图?我是否需要转换它或在函数中指定其他内容?

由于

1 个答案:

答案 0 :(得分:11)

我认为您可以使用barh

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()

graph