alperyildirim
alperyildirim

Reputation: 37

Removing a column permanently from a data frame in Python

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?

Upvotes: 1

Views: 1799

Answers (1)

MarianD
MarianD

Reputation: 14191

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.

Upvotes: 4

Related Questions