【问题标题】:Key Error: None of [Int64Index([...]dtype='int64')] are in the [columns]关键错误:[Int64Index([...]dtype='int64')] 都不在 [columns] 中
【发布时间】:2021-04-28 02:28:53
【问题描述】:

这是我的数据框:

    a        b      c
0   1971    2154    203020339
1   1972    2648    191489250
2   1973    2690    193377651
3   1974    2676    201291002
4   1975    3276    275380446

我试图用它制作一个非常简单的情节:

df.plot(x = df['a'], y = df['b'])

但我不断收到关键错误消息:

None of [Int64Index([1971, 1972, 1973, 1974, 1975], dtype='int64')] are in the [columns]

我尝试使用将列 [a] 转换为 DateTime,但仍然收到相同的错误消息。

df['a'] = pd.to_datetime(df['a'], format='%Y')

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    在熊猫图中,你已经有了一个数据框,所以列名必须是一个名字。

    df.plot(x='a', y='b')
    

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 2020-05-10
      • 2019-09-04
      • 2019-09-16
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 2021-01-17
      • 2013-01-06
      相关资源
      最近更新 更多