使用train.rename修改列的名字,例:
print(train.columns.values)
train.rename(columns={'收率':'y','样本id':"id"},inplace=True)
print(train.columns.values)
运行结果:
#修改前
['样本id' 'A1' 'A2' 'A3' 'A4' 'A6' 'A8' 'A10' 'A12' 'A15' 'A17' 'A19' 'A20'
'A21' 'A22' 'A25' 'A27' 'A28' 'B1' 'B2' 'B4' 'B6' 'B8' 'B9' 'B10' 'B11'
'B12' 'B14' '收率']
#修改后
['id' 'A1' 'A2' 'A3' 'A4' 'A6' 'A8' 'A10' 'A12' 'A15' 'A17' 'A19' 'A20'
'A21' 'A22' 'A25' 'A27' 'A28' 'B1' 'B2' 'B4' 'B6' 'B8' 'B9' 'B10' 'B11'
'B12' 'B14' 'y']