Python 3.0 error in Label Encoding

python
label_encoding

#1
 from sklearn.preprocessing import LabelEncoder
var_mod = ['Gender','Married','Dependents','Education','Self_Employed','Property_Area','Loan_Status']
le = LabelEncoder()
for i in var_mod:
    df[i] = le.fit_transform(df[i])
df.dtypes 

when i run this code in python3.0 (Anaconda) , m getting " ‘<’ not supported between instances of ‘str’ and ‘float’ "


#2

Hi,

Please use the below code:

from sklearn.preprocessing import LabelEncoder
var_mod = ['Gender','Married','Dependents','Education','Self_Employed','Property_Area','Loan_Status']
df[var_mod] = df[var_mod].astype('str')
le = LabelEncoder()
for i in var_mod:
   df[i] = le.fit_transform(df[i])