使用 get dummies() 进行单热编码
>>> df = pd.DataFrame({'Name':['John Smith', 'Mary Brown'],
'Gender':['M', 'F'], 'Smoker':['Y', 'N']})
>>> print(df)
Gender Name Smoker
0 M John Smith Y
1 F Mary Brown N
>>> df_with_dummies = pd.get_dummies(df, columns=['Gender', 'Smoker'])
>>> print(df_with_dummies)
Name Gender_F Gender_M Smoker_N Smoker_Y
0 John Smith 0.0 1.0 0.0 1.0
1 Mary Brown 1.0 0.0 1.0 0.0