如何用熊猫做一个简单的情节

时间:2016-03-25 05:56:31

标签: python pandas

我想用pandas做一个简单的情节,但是得到了这个错误:

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

df = pandas.read_csv("volvo_volvo.csv");
dfw = pandas.DataFrame(data = df, columns=['PriceDisplay','Year','Odometer'])
y = df.PriceDisplay.values
x = df.Odometer.values

df.plot(x=x, y=y, marker='.')
plt.show()

IndexError:指数超出范围

CSV文件列价格和里程表:

PriceDisplay    IsBold  Make    Transmission    Category    Owners  HasFreeShipping Year
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005
17985   TRUE    Audi    Automatic   0001-0268-0271- 0   TRUE    2005

Odometer
61988
61988
61988
61988
61988
61988
61988
61988
61988
61988
61988
61988
61988
61988

打印出x和y变量:

打印(x)的

打印(y)的

[61988 61988 61988 61988 61988 61988 61988 61988 61988 61988 61988 61988
 61988 61988]
[17985 17985 17985 17985 17985 17985 17985 17985 17985 17985 17985 17985
 17985 17985]

1 个答案:

答案 0 :(得分:0)

只需在[{1}}和.values的作业中省略x