簡體   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