如何阅读csv避免索引?

时间:2017-10-15 13:42:30

标签: python pandas

csv数据是这样的:

,fixed acidity,volatile acidity,citric acid,residual sugar,chlorides,free sulfur dioxide,total sulfur dioxide,density,pH,sulphates,alcohol,quality
0,7.0,0.27,0.36,20.7,0.045,45.0,170.0,1.001,3.0,0.45,8.8,6
1,6.3,0.3,0.34,1.6,0.049,14.0,132.0,0.994,3.3,0.49,9.5,6

我希望这是我的计划:

data = pd.read_csv('train.csv',delimiter=',')
group = data.drop('quality',axis=1).values
print(group[0])

我希望结果为7.0,0.27,0.36,20.7,0.045,45.0,170.0,1.001,3.0,0.45,8.8,6,但结果为0,7.0,0.27,0.36,20.7,0.045,45.0,170.0,1.001,3.0,0.45,8.8。那么如何避免索引列?

1 个答案:

答案 0 :(得分:2)

首先,之前您的数据未转换为索引存在问题,因此需要index_col=[0]。然后在调用.values之后省略第一列:

data = pd.read_csv('train.csv',delimiter=',', index_col=[0])

或者:

data = pd.read_csv('train.csv', index_col=[0])