繁体   English   中英

关键错误:[Int64Index([…]dtype='int64')] 均不在 [columns] 中

[英]Key Error: None of [Int64Index([…]dtype='int64')] are in the [columns]

所以这是我的 DataFrame:

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

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

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')

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

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

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM