I have a dataset full of categorical values that are not encoded at the moment. For instance, I have a variable called condition
which has these values:
Very Excellent
, Excellent
, Very Good
I want to encode these (give them integer values) so that I can use them as categorical dummy variables in a regression. However, I have lots of these in my Data Frame so I'd like to iterate over each column and encode all dtype objects. This is my attempt:
import pandas as pd
from sklearn.preprocessing import LabelEncoder
enc=LabelEncoder()
for column in df_06:
if df_06["column"].values==object:
df_06["column"]=enc.fit_transform(df_06["column"])
My dataframe is
Error:
<ipython-input-48-ea6aec86108f> in <module>()
1 for column in df_06:
----> 2 if df_06[column].values==object:
3 df_06[column]=enc.fit_transform(df_06[column])
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()