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
658 views
in Technique[技术] by (71.8m points)

python - I'm getting an error in the following program as KeyError Traceback (most recent call last)

Here is my code-

import pandas as pd

df5=pd.read_csv(r'C:Anaconda3airtravel.csv')

print(df5)

   Month   "1958"   "1959"   "1960"
0    JAN      340      360      417
1    FEB      318      342      391
2    MAR      362      406      419
3    APR      348      396      461
4    MAY      363      420      472
5    JUN      435      472      535
6    JUL      491      548      622
7    AUG      505      559      606
8    SEP      404      463      508
9    OCT      359      407      461
10   NOV      310      362      390
11   DEC      337      405      432

But when I try to access this:-

print(df5['1960'])

I get an error.

KeyError: '1960'

I can't understand why is that happening. File link: https://people.sc.fsu.edu/~jburkardt/data/csv/csv.html

Thanks

question from:https://stackoverflow.com/questions/65941382/im-getting-an-error-in-the-following-program-as-keyerror-traceback-most-recent

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

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...