Sklearn OrdinalEncoder Example
Python
How to encode categorical features as integers.
1| from sklearn.preprocessing import OrdinalEncoder 2| 3| ordinal_encoder = OrdinalEncoder() 4| 5| ordinal_encoder.fit(df['Sex'].values.reshape(-1, 1)) 6| 7| df['Sex'] = ordinal_encoder.transform(df['Sex'].values.reshape(-1, 1))
142
127
122
115