WeCodeAcademy

Missing Values (NaN)

Real data has gaps. NumPy marks a missing number as NaN ("not a number"). Any normal calculation that touches a NaN becomes NaN, which can silently spoil a result. Use np.isnan to find them, and the nan versions of the aggregates (np.nanmean, np.nansum, np.nanmax) to skip them. Test for NaN with np.isnan, never with ==, because NaN is not equal even to itself.

Examplepython
Open in editor »
Quick check

Why does `np.mean` of an array containing NaN return NaN?

Your turn: write the code

Print the largest reading, ignoring the missing values.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.