【问题标题】:Converting index to name pandas for graphing将索引转换为名称 pandas 以进行绘图
【发布时间】:2017-10-29 06:41:01
【问题描述】:

我有一个数据框并想要绘制它。

但是,当我绘制它时,它给出了索引名称而不是国家名称。我怎样才能输入国家名称而不是索引?

谢谢

【问题讨论】:

    标签: pandas matplotlib indexing graph


    【解决方案1】:

    首先通过set_indexcountry列创建index,然后使用Series.plot.bar

    e.set_index('country')['total_serving'].plot.bar()
    #same as
    #e.set_index('country')['total_serving'].plot(kind='bar')
    

    或使用DataFrame.plot.bar:

    e.plot.bar(x='country', y='total_serving')
    #same as
    #e.plot.bar(x='country', y='total_serving', kind='bar')
    

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 2021-12-17
      • 2019-05-13
      • 2019-05-04
      • 2019-07-26
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多