Sometimes, we want to check for NaN values with Python.
In this article, we’ll look at how to check for NaN values with Python.
How to check for NaN values with Python?
To check for NaN values with Python, we can use the math.isnan
method.
For instance, we write
import math
x = float('nan')
is_nan = math.isnan(x)
to call math.isnan
on x
to check if x
is NaN.
Since x
is NaN, is_nan
is True
.
Conclusion
To check for NaN values with Python, we can use the math.isnan
method.