pandas.read_csv 参数 index_col=0

index_col : int or sequence or False, default None

用作行索引的列编号或者列名,如果给定一个序列则有多个行索引。
如果文件不规则,行尾有分隔符,则可以设定index_col=False 来使得pandas不使用第一列作为行索引。
 
如:
train_df = pd.read_csv('./input/train.csv')
print train_df.columns
结果:

Index([u'Id', u'MSSubClass', u'MSZoning', u'LotFrontage', u'LotArea',
u'Street', u'Alley', u'LotShape', u'LandContour', u'Utilities',
u'LotConfig', u'LandSlope', u'Neighborhood', u'Condition1',
u'Condition2', u'BldgType', u'HouseStyle', u'OverallQual',
u'OverallCond', u'YearBuilt', u'YearRemodAdd', u'RoofStyle',
u'RoofMatl', u'Exterior1st', u'Exterior2nd', u'MasVnrType',。。。]

train_df = pd.read_csv('./input/train.csv', index_col=0)
结果:

Index([u'MSSubClass', u'MSZoning', u'LotFrontage', u'LotArea', u'Street',
u'Alley', u'LotShape', u'LandContour', u'Utilities', u'LotConfig',
u'LandSlope', u'Neighborhood', u'Condition1', u'Condition2',
u'BldgType', u'HouseStyle', u'OverallQual', u'OverallCond',
u'YearBuilt', u'YearRemodAdd', u'RoofStyle', u'RoofMatl',
u'Exterior1st', u'Exterior2nd', u'MasVnrType',。。。]



原文地址:https://www.cnblogs.com/TMatrix52/p/7717756.html