Borut Flis
Borut Flis

Reputation: 16395

Why do you need to reassign variable after every change to Pandas Dataframe?

Pandas Dataframes are suposed to be mutable, like lists. Therefore a change in the dataframe should be reflected in the previous reference.

However:

df.drop(to_delete)

Does not delete the indexes in the variable to delete.

df=df.drop(to_delete)

You have to reassign the variable. Why is that? Is the new the df than the same instance of the object?

Upvotes: 1

Views: 406

Answers (1)

BENY
BENY

Reputation: 323326

We have the inplace

df.drop(to_delete, inplace=True)

Upvotes: 1

Related Questions