weixin_44069903
Ericalia
2019-04-09 21:24

为什么x.shape[1]会显示错误,为什么这个列向量只有一个参数

  • 机器学习
  • 数据挖掘

最近用python编写一个线性回归的算法,在使用pandas读取列数据后无法得到列数据的完整索引,使用x.shape[1](显示列数)时代码报错,恳求大神指导

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False


data=pd.read_csv('E:\machine learning datasets\Salary_Data.csv')

x=data['YearsExperience']
print(x.shape[1])

runfile('C:/Users/Administrator/untitled3.py', wdir='C:/Users/Administrator')
Traceback (most recent call last):

  File "<ipython-input-55-5248b051639a>", line 1, in <module>
    runfile('C:/Users/Administrator/untitled3.py', wdir='C:/Users/Administrator')

  File "D:\anaconda1\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

  File "D:\anaconda1\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Administrator/untitled3.py", line 18, in <module>
    print(x.shape[1])

IndexError: tuple index out of range
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答