I\'m facing this error for multiple variables even treating missing values. For example:
le = preprocessing.LabelEncoder()
categorical = list(df.select_dtypes(in
As string data types have variable length, it is by default stored as object type. I faced this problem after treating missing values too. Converting all those columns to type 'category' before label encoding worked in my case.
df[cat]=df[cat].astype('category')
And then check df.dtypes and perform label encoding.