Im trying to LabelEncode particular columns of a Dataframe. I have stored those column names in a list(cat_features). Now i want to use a For loop to iterate through this list's elements (which are strings) and use those elements to access dataframe's column. but it says
TypeError: argument must be a string or number
Since Im accessing the element of the list which is already a string. so i dont understand why it throw that error. Please help me understand why it doesn't work and what can I do to make it work.
cat_features = [x for x in features if x not in features_to_scale]
from sklearn.preprocessing import LabelEncoder
for feature in cat_features:
le = LabelEncoder()
dataframe[feature] = le.fit_transform(dataframe[feature])