0

I try to analyze the open data,and I tried to plot the scatter figure, but encounter the problem is always show the error.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# 讀入 csv 文字檔
csv_file = ("../ff0002fiac-4.csv")
data = pd.read_csv(csv_file,names=['a','b','c','d','e','f'])
print(data.head(5))
#df=pd.DataFrame(data)
years=data['a']
people=data['b']
print(years)
print(people)
data.plot(kind='line',x=years,y=people)
plt.show()

I expect to show the scatter figure, but the result is error.

Here is the data:

a     b       c      d      e      f
0  100  3.56  120905  89608  72562   6686
1  101  3.43  118800  90229  73645   7858
2  102  3.47  116210  90236  73148   9170
3  103  3.17  105977  82889  68020   7949
4  104  3.36  121654  95517  77258  10049

and show the error below

KeyError: '[100 101 102 103 104 105 106] not in index'

1 Answer 1

3

From the pandas.DataFrame.plot documentation, the x and y parameters should be labels or positions. You're probably meaning to do this:

data.plot(kind='line',x='a',y='b')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.