我有以下DataFrame:
voting_result project scene
Bad ccus 345943
Good ccus 311129
Bad ccus 309082
Bad ccus 331613
Good ccus 331615
Not Sure ccus 331616
通过遵循规则Pandas
} encode
对{'Bad':0, 'Good':1, 'Not Sure':2
voting_result列到整数的方式是什么
voting_result project scene
0 ccus 345943
1 ccus 311129
0 ccus 309082
0 ccus 331613
1 ccus 331615
2 ccus 331616
由于
答案 0 :(得分:5)
dictionary
使用map
:
d = {'Bad':0, 'Good':1, 'Not Sure':2}
df['voting_result'] = df['voting_result'].map(d)
print (df)
voting_result project scene
0 0 ccus 345943
1 1 ccus 311129
2 0 ccus 309082
3 0 ccus 331613
4 1 ccus 331615
5 2 ccus 331616