Skip to content
Justice Tech School

Missing Values: NaN

NaN marks missing numbers. Normal sums become NaN, so use nansum, nanmean and isnan.

Example
import numpy as np
a = np.array([1.0, np.nan, 3.0])
print(a.sum(), np.nansum(a), np.nanmean(a))
print(np.isnan(a))
print(np.nan == np.nan)

Result

nan 4.0 2.0
[False  True False]
False

Exercise

Find NaN values.

np.(a)

Quiz Test

Is NaN equal to NaN?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.