python pandas在编译时显示错误

时间:2016-12-15 16:08:04

标签: python pandas numpy

我是python的新手,我第一次使用熊猫。我在http://pastebin.com/VxeUT5zW看到了一个帖子并试图实现这一点。我正在使用python 3.4并安装了所有必需的软件包。但我得到一些错误。我试图自己纠正它,检查互联网和所有..但我无法纠正它。请帮我纠正。

 # coding=utf-8
# Linear Regression Realization (http://dataaspirant.com/2014/12/20/linear-      regression-implementation-in-python/)

# input_data.csv:
# square_feet;price
# 150;6450
# 200;7450
# 250;8450
# 300;9450
# 350;11450
# 400;15450
# 600;18450

# Required Packages
 import matplotlib.pyplot as plt
 import pandas as pd
 from sklearn import linear_model


# Function to get data
def get_data(file_name):
data = pd.read_csv('C:\Python34\data\input_data.csv', sep=";")
x_parameter = []
y_parameter = []
# TODO: Replace the names of the fields 'square foot', 'price' for your own       values
for single_square_feet in data['square_feet']:
    x_parameter.append([float(single_square_feet)])

for single_price_value in data['price']:
    y_parameter.append(float(single_price_value))
return x_parameter, y_parameter


 # Function for Fitting our data to Linear model
    # noinspection PyPep8Naming
 def linear_model_main(x_parameters, y_parameters, predict_value):
# Create linear regression object
regr = linear_model.LinearRegression()
regr.fit(x_parameters, y_parameters)
# noinspection PyArgumentList
predict_outcome = regr.predict(predict_value)
predictions = {'intercept': regr.intercept_, 'coefficient': regr.coef_,    'predicted_value': predict_outcome}
return predictions


# Function to show the resutls of linear fit model
def show_linear_line(x_parameters, y_parameters):
# Create linear regression object
regr = linear_model.LinearRegression()
regr.fit(x_parameters, y_parameters)
plt.scatter(x_parameters, y_parameters, color='blue')
# noinspection PyArgumentList
plt.plot(x_parameters, regr.predict(x_parameters), color='red', linewidth=4)
# Supress axis value
plt.xticks(())
plt.yticks(())
plt.show()


X, Y = get_data('C:\Python34\data\input_data.csv')
predicted_value = 700
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: {0}'.format(result['intercept']))
print('Coefficient: {0}'.format(result['coefficient']))
print('Predicted Value: {0}'.format(result['predicted_value']))
show_linear_line(X, Y)

我得到的错误是:

Compilation error scrnshot

Microsoft Windows [版本6.3.9600] (c)2013 Microsoft Corporation。保留所有权利。

C:\用户\维克多> CD \

C:\>Python34\python.exe C:\Python34\data\cp.py
Traceback (most recent call last):
File "C:\Python34\data\cp.py", line 60, in <module>
X, Y = get_data('C:\Python34\data\input_data.csv')
File "C:\Python34\data\cp.py", line 22, in get_data
data = pd.read_csv('C:\Python34\data\input_data.csv', sep=";")
File "C:\Python34\lib\site-packages\pandas\io\parsers.py", line 645, in    parser
_f
 return _read(filepath_or_buffer, kwds)
 File "C:\Python34\lib\site-packages\pandas\io\parsers.py", line 400, in _read
data = parser.read()
File "C:\Python34\lib\site-packages\pandas\io\parsers.py", line 938, in read
ret = self._engine.read(nrows)
File "C:\Python34\lib\site-packages\pandas\io\parsers.py", line 1507, in read
data = self._reader.read(nrows)
File "pandas\parser.pyx", line 846, in pandas.parser.TextReader.read   (pandas\parser.c:10364)
File "pandas\parser.pyx", line 868, in  pandas.parser.TextReader._read_low_memory (pandas\parser.c:10640)
File "pandas\parser.pyx", line 922, in pandas.parser.TextReader._read_rows (pandas\parser.c:11386)
File "pandas\parser.pyx", line 909, in pandas.parser.TextReader._tokenize_rows(pandas\parser.c:11257)
File "pandas\parser.pyx", line 2018, in pandas.parser.raise_parser_error (pandas\parser.c:26979)pandas.io.common.CParserError: Error tokenizing data. C error: Expected 1 fields in line 37, saw 2


C:\>

请帮帮我 提前谢谢

0 个答案:

没有答案