colorMap = {elem:index+1 for index,elem in enumerate(set(train_df["salary"]))}
train_df['salary'] = train_df['salary'].map(colorMap)
train_df
把每个特征名变成0 1 2 3 4 5 这种数字
写的函数 传递的是pandas读取的csv
def hard_code(train_df):
dest_feature=["ProductCD","card4"]
for name in dest_feature:
colorMap = {elem:index+1 for index,elem in enumerate(set(train_df[name]))}
train_df[name] = train_df[name].map(colorMap)
return train_df
train_df=hard_code(train_df)
train_df