使用Pandas Value_Counts和matplotlib

W4K*_*1NG 9 python plot matplotlib pandas

我使用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
Run Code Online (Sandbox Code Playgroud)

我现在想用matplotlib绘制这些值,即"plt.barh(CountStatus)",但是我不断收到错误:ValueError:不兼容的大小:参数'width'必须是长度7或标量.

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

谢谢

jez*_*ael 13

我想你可以用barh:

CountStatus.plot.barh()
Run Code Online (Sandbox Code Playgroud)

样品:

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

CountStatus.plot.barh()
Run Code Online (Sandbox Code Playgroud)

图形