Use math.isnan:
>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
Answer from gimel on Stack Overflow Top answer 1 of 16
2215
Use math.isnan:
>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
2 of 16
626
The usual way to test for a NaN is to see if it's equal to itself:
def isNaN(num):
return num != num
09:49
Learning Python: Handling Empty Values, None, pd.NaN - YouTube
NaN in Pandas || Lesson 1.9 || Python for Data Science ...
00:43
How to create NaN in Python
01:00
[Python] How to Tell if a Variable is a NaN in Python Short Video ...
04:41
How to turn NaN and floats into integers by using Pandas dataframe ...
6.8. Python | Pandas - NaN #python
Python Course
python-course.eu › numerical-programming › dealing-with-nan.php
33. Dealing with NaN | Numerical Programming | python-course.eu
February 3, 2025 - Python knows NaN values as well.
Educative
educative.io › answers › how-to-assign-nan-to-a-variable-in-python
How to assign NaN to a variable in Python
NaN stands for “Not a Number,” which represents unrepresentable numeric values in Python.
W3Schools
w3schools.com › PYTHON › ref_math_nan.asp
Python math.nan Constant
Python Examples Python Compiler ... Study Plan Python Interview Q&A Python Training ... The math.nan constant returns a floating-point nan (Not a Number) value....
Pandas
pandas.pydata.org › docs › user_guide › missing_data.html
Working with missing data — pandas 3.1.1 documentation
NA is a scalar (singleton) used to represent missing values for nullable dtypes. The goal of NA is to provide a “missing” indicator that can be used consistently across data types (instead of np.nan, None or pd.NaT depending on the data type).
YouTube
youtube.com › watch
Handling NAN values with Python (tutorial) - YouTube
When working with data, it's common to encounter NaN values, which stand for "Not a Number." NaN values can arise due to missing data, errors in data collect...
Published: February 17, 2024
Readthedocs
datatest.readthedocs.io › en › stable › how-to › nan-values.html
How to Deal With NaN Values — datatest 0.11.1 documentation
NaN values can also be created in any Python version using float('nan').
NumPy
numpy.org › doc › stable › user › misc.html
Miscellaneous — NumPy v2.5 Manual
>>> myarr = np.array([1., 0., np.nan, 3.]) >>> np.nonzero(myarr == np.nan) (array([], dtype=int64),)
LWN.net
lwn.net › Articles › 869231
Revisiting NaNs in Python [LWN.net]
September 15, 2021 - NaNs are defined in the IEEE 754 floating-point standard, which Python follows, as special values for quantities that cannot be represented by the hardware. This can happen as a result of operations like division by zero or taking the square root of a negative number, though Python raises an ...
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.1 Manual
>>> import numpy as np >>> np.isnan(np.nan) True >>> np.isnan(np.inf) False >>> np.isnan([np.log(-1.),1.,np.log(0)]) array([ True, False, False])