Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

python - 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')
question from:https://stackoverflow.com/questions/65865201/key-error-none-of-int64index-dtype-int64-are-in-the-columns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...