Reputation: 1
col = ['date','age','race', 'sex','procedure1', 'procedure2', 'procedure3', 'a_diag', 'p_diag','s_diag1','s_diag2', 's_diag3', 's_diag4', 's_diag5']
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
for i in col:
df[i] = le.fit_transform(df[i].astype('object'))
For the above code, I get the following error:
'<' not supported between instances of 'str' and 'int'
Upvotes: 0
Views: 468
Reputation: 6280
I would suggest you to run:
df.dtypes
first, to check which columns are already a numeric column, the output should look like this:
date object
age int32
I would exclude all numeric columns then from your loop. Then change the loop code to:
df[i] = le.fit_transform(df[i].astype('str'))
If there is still an error, check this out: TypeError: '<=' not supported between instances of 'str' and 'int'
Upvotes: 1