Skip to content
Advertisement

Change Series inplace in DataFrame after applying function on it

I’m trying to use pandas in order to change one of my columns in-place, using simple function.

After reading the whole Dataframe, I tried to apply function on one Series:

JavaScript

And it’s working great. The only problem occurs when I try to put it back into my DataFrame:

JavaScript

or:

JavaScript

Throwing the following warning:

JavaScript

Of Course, I can set the DataFrame using the long form of:

JavaScript

But is there no other, easier and more syntactic-nicer way to do it?

Thanks!

Advertisement

Answer

Use loc:

JavaScript
Advertisement