简体   繁体   English

使用matplotlib进行绘图

[英]Using the matplotlib to plot

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' KeyError:“ [100101102103104105106]不在索引中”

From the pandas.DataFrame.plot documentation , the x and y parameters should be labels or positions. pandas.DataFrame.plot文档中xy参数应为标签或位置。 You're probably meaning to do this: 您可能是想这样做:

data.plot(kind='line',x='a',y='b')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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