Reputation: 327
I have the data like below, I need to encode the variables, but LabelEncoder is not encoding the strings
My data looks like below
Delivery_class
First Class
Same Day
Second Class
Standard Class
X=filtered_df.iloc[:, 1]
labelencoder_X = LabelEncoder()
X.values[:,1] = labelencoder_X.fit_transform(X.values[:,1].astype(str))
even after running the abovr code the strings remains same.
Please advice, I am a beginner in XGBoost
Upvotes: 0
Views: 180
Reputation: 29752
Don't assign back to X.values
. Use X.iloc
:
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
X.iloc[:, 1] = le.fit_transform(X.values[:, 1].astype(str))
Output:
Index Ship_Mode
0 0 0
1 1 0
2 2 1
3 3 1
4 4 0
5 5 2
Upvotes: 1