1

In a given data frame mydf, I removed a column from the data frame through:

mydf.drop('Z', axis=1)

However, in the following parts, the removed column Z is still there, e.g., when I write print(mydf.sum()) after the previous cell, it gives me the sum of column Z with the sum of other columns. How can I delete the column Z permanently?

2
  • 4
    .drop by default returns a new dataframe. specify inplace=True if you don't want to re-assign mydf Commented Dec 25, 2020 at 21:14
  • I got it. Thanks! Commented Dec 25, 2020 at 23:43

1 Answer 1

4

You have to assign it back to mydf, if you want to reach a permanent change, i.e. do

mydf = mydf.drop('Z', axis=1)

instead.

Sign up to request clarification or add additional context in comments.

1 Comment

It makes sense. Thank you so much.

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.