简体   繁体   中英

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

So here's my DataFrame:

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

I tried to make a very simple plot with it:

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

But I keep getting a Key Error message:

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

I tried to use convert column [a] to DateTime but I still got the same error message.

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

In the pandas plot, you already have a data frame, so the column name must be a name.

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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