0

What I want to do is write a line of code that resets in the indices on some data frames. I thought I could write something like this

X_train, X_test_, y_train, y_test = train_test_split(X,y)
map(lambda x: x.reset_index(drop=True,inplace=True),
                 [X_train, X_test_, y_train, y_test]) 

But it doesn't have the desired result. Suggestions?

1 Answer 1

2

map is a lazy operation. It doesn't run until you iterate over the map. You can achieve your desired result by simply running a list comprehension:

X_train, X_test_, y_train, y_test = [
    df.reset_index(drop=True)
    for df in train_test_split(X,y)
]
Sign up to request clarification or add additional context in comments.

Comments

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.