How to apply LabelEncoder for a specific column in Pandas dataframe

You can try as following:

le = preprocessing.LabelEncoder()
df['label'] = le.fit_transform(df.label.values)

Or following would work too:

df['label'] = le.fit_transform(df['label'])

It will replace original label values in dataframe with encoded labels.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)