I have a list of columns in my large dataframe that are catergorical and I'm trying to encode them because some of the algo's I'm using do not accept strings(knn for example).
Here's my code:
#encode categories
from sklearn.preprocessing import LabelEncoder
# LabelEncoder
le = LabelEncoder()
# dataImputed[catgoricalValues] = dataImputed[catgoricalValues].apply(le.fit_transform) #didn't work
dataImputed[catgoricalValues] = le.fit_transform(dataImputed[catgoricalValues].astype(str))
I got this error:
ValueError: y should be a 1d array, got an array of shape (490546, 11) instead.
What can I do to only encode those values in my catgoricalValues
list while maintaining all other values in my dataframe?