1

I have a Series that look like this:

13624    A
25257    D
15359    D
26226    D
10797    D
        ..
9733     D
25121    D
10143    C
1448     B
13627    B
Name: points, Length: 10189, dtype: object

And I want to apply the LabelEncoder() function from sklearn.preprocessing and replace all the values.

The le.fit_transform(y_train) function returns this:

array([0, 3, 3, ..., 2, 1, 1])

This array is ordered by the original index, so the idea is to replace exactly the value column with this array.

How can I do that?

1 Answer 1

3

You can try creating a new series with the same index and reassign back:

y_train = pd.Series(le.fit_transform(y_train), index=y_train.index)
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, good idea. Simple and it is working. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.