【发布时间】:2017-10-29 06:41:01
【问题描述】:
我有一个数据框并想要绘制它。
但是,当我绘制它时,它给出了索引名称而不是国家名称。我怎样才能输入国家名称而不是索引?
谢谢
【问题讨论】:
标签: pandas matplotlib indexing graph
我有一个数据框并想要绘制它。
但是,当我绘制它时,它给出了索引名称而不是国家名称。我怎样才能输入国家名称而不是索引?
谢谢
【问题讨论】:
标签: pandas matplotlib indexing graph
首先通过set_index从country列创建index,然后使用Series.plot.bar:
e.set_index('country')['total_serving'].plot.bar()
#same as
#e.set_index('country')['total_serving'].plot(kind='bar')
e.plot.bar(x='country', y='total_serving')
#same as
#e.plot.bar(x='country', y='total_serving', kind='bar')
【讨论】: