【问题标题】:Setting index and plotting at the same time同时设置索引和绘图
【发布时间】:2018-04-05 10:42:09
【问题描述】:

我正在尝试使用 Jupyter 笔记本绘制一个简单的折线图,使用一列作为索引,另一列作为一列。我试过了:

dataframe.set_index('Year'),['AUD'].plot()

这会导致'list' object has no attribute 'plot' 错误。

我可以使用Year 作为索引创建一个新的数据框,然后绘制AUD,但是我可以在简单地绘制一行时获得一些帮助吗?

【问题讨论】:

  • 你有语法错误,去掉逗号:dataframe.set_index('Year'),['AUD'].plot() --> dataframe.set_index('Year')['AUD'].plot()
  • 谢谢大家!!!!!!

标签: python pandas dataframe jupyter-notebook


【解决方案1】:

效果很好:

df = pd.DataFrame({'year':[101,102,103,104],'aud':[34,45,46,67]})
df.set_index('year')['aud'].plot()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 2021-07-20
    • 2015-10-28
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多