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

Handling of NaN values in mathematical operations

The NaN values are handled differently in pandas than in NumPy. We have seen this in earlier chapters, but it is worth revisiting here. This is demonstrated using the following example:

When a NumPy function encounters a NaN value, it returns NaN. Pandas functions typically ignore the NaN values and continue processing the function as though the NaN values were not part of the Series object.

Note that the mean of the preceding series was calculated as (1+2+3)/3 = 2, not (1+2+3)/4 or (1+2+0+4)/4. This verifies that NaN is totally ignored and not even counted as an item in Series.

More specifically, ...

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