python与回归分析

python与回归分析,python,numpy,matplotlib,Python,Numpy,Matplotlib,我试图用python进行回归分析,但是有错误。请帮帮我 我已经导入了以下模块: import pandas as pd import numpy as np from scipy import stats from statsmodels.sandbox.regression.predstd import wls_prediction_std import statsmodels.api as sm import matplotlib.pyplot as plt %pylab 我得到的数据如

我试图用python进行回归分析,但是有错误。请帮帮我

我已经导入了以下模块:

import pandas as pd 
import numpy as np
from scipy import stats
from statsmodels.sandbox.regression.predstd import wls_prediction_std
import statsmodels.api as sm
import matplotlib.pyplot as plt
%pylab
我得到的数据如下:

data=pd.read_csv('file.csv',names['storedate','amount','location'])
x=data['amount']
y=data['location']
AttributeError: 'numpy.ndarray' object has no attribute 'name'
然后我定义了x和y,如下所示:

data=pd.read_csv('file.csv',names['storedate','amount','location'])
x=data['amount']
y=data['location']
AttributeError: 'numpy.ndarray' object has no attribute 'name'
我试着做下面的代码 x=sm.add_constantx,prepend=False

但第一个错误如下所示:

data=pd.read_csv('file.csv',names['storedate','amount','location'])
x=data['amount']
y=data['location']
AttributeError: 'numpy.ndarray' object has no attribute 'name'
下面的代码也有错误:

model = sm.OLS(y,x)
results = model.fit()
信息是:

can't multiply sequence by non-int of type 'float'

我认为,错误消息不能将序列乘以“float”类型的非int,因为x和y不是numpy数组。使用

x = np.array(data['amount'])
y = np.array(data['location'])
而不是您当前对x和y的定义