本文仅作为学习记录,如有侵权,请随时与我联系!
1、map少量直接映射
str_mapping = {'x':1, 'y':2, 'z':3}
df['AA'] = df['AA'].map(str_mapping)
2、map大量映射
str_mapping = {label: idx for idx, label in enumerate(np.unique(df['AA']))}
df['AA'] = df['AA'].map(str_mapping)
3、one_hot编码
color_encoder=pd.get_dummies(df[['color']])
df2=pd.concat([color_encoder,df],axis=1)