Nasri
Nasri

Reputation: 545

encode dataframe with python using encoder

I 'am trying to encode a dataframe with LabelEncoder() before creating my machine learning model

here the code :

from sklearn.preprocessing import LabelEncoder
# LabelEncoder
le = LabelEncoder()

# apply "le.fit_transform"
df_encoded = data1.apply(le.fit_transform)
print(df_encoded)
print(le.classes_)

But I got this error :

TypeError: ("'<' not supported between instances of 'str' and 'NoneType'", 'occurred at index SACC_MARKET_SEGMENT')

Anyone can help ùme to resolve this problem? tahnk you

Upvotes: 0

Views: 397

Answers (1)

Rafa&#243;
Rafa&#243;

Reputation: 599

There can be a problem with type of your data. I don't know what's your desired data type, but you can try converting data1 to string:

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()

df_encoded = le.fit_transform(data1.astype(str))
print(df_encoded)
print(le.classes_)

Upvotes: 1

Related Questions