O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Replacing values

We previously saw how the .fillna() method can be used to replace the NaN values with a value of your own decision. The .fillna() method can actually be thought of as an implementation of the .map() method that maps a single value, NaN, to a specific value.

Even more generically, the .fillna() method itself can be considered a specialization of a more general replacement that is provided by the .replace() method. This method provides more flexibility by being able to replace any value (not just NaN) with another value.

The most basic use of the .replace() method is to replace an individual value with another:

It is also possible ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required