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

Filling in missing data

The .fillna() method can be used to replace the NaN values with a specific value, instead of having them propagated or flat out ignored. The following demonstrates this by filling the NaN values with 0:

Be aware that this causes differences in the resulting values. As an example, the following code shows the result of applying the .mean() method to a DataFrame object with the NaN values, as compared to a DataFrame object that has its NaN values filled with 0:

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