Use math.isnan:

>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
Answer from gimel on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-for-nan-values-in-python
Check For NaN Values in Python - GeeksforGeeks
July 23, 2025 - In Python, NaN stands for "Not a Number". It is a special floating-point value defined in the IEEE 754 floating-point standard, used to represent undefined or unrepresentable numerical results.
🌐
Turing
turing.com › kb › nan-values-in-python
Check For NaN Values in Python
The isna() function returns a Boolean Series where True represents NaN values and False represents non-NaN values. In Python, you can also use the comparison operator != to check for NaN values. NaN values are considered unequal to all other values, including themselves.
🌐
Note.nkmk.me
note.nkmk.me › home › python
What is nan in Python (float('nan'), math.nan, np.nan) | note
May 9, 2023 - Convert between bool (True/False) and other types in Python · As you can see with bool(), nan is evaluated as True.
🌐
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.
Find elsewhere
🌐
Digis
digiscorp.com › python-check-if-value-is-nan-a-complete-overview
Python Check If Value Is NaN: A Complete Overview
September 7, 2026 - Learn how to check if a value is NaN Python using methods like numpy.isnan, math.isnan, and pandas.isna. Discover the best practices for identifying and handling NaN values efficiently in your Python projects.
🌐
Medium
medium.com › data-science › navigating-the-hell-of-nans-in-python-71b12558895b
Navigating The Hell of NaNs in Python | by Julia Di Russo | TDS Archive | Medium
November 8, 2019 - NaN stands for Not A Number and is a common missing data representation. It is a special floating-point value and cannot be converted to any other type than float. It was introduced by the IEEE Standard for Binary Floating-Point for Arithmetic ...
🌐
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....
🌐
Tenable®
tenable.com › blog › python-nan-injection
Python NaN Injection - Blog | Tenable®
July 11, 2022 - Python is often referred to as ... duck.’ However, a variable can be injected with a string called NaN (which stands for Not a Number) and when it encounters another variable, it can consume it....
🌐
Python.org
discuss.python.org › python help › question about `float('nan')`
Question about `float('nan')` - Python Help - Discussions on Python.org
March 4, 2026 - I am working on a talk I would like to give at PyOhio about float(‘nan’) and I was wondering if anyone knows why each call to float(‘nan’) returns a different instance? TIA.
🌐
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
🌐
Medium
medium.com › data-science › nan-values-in-the-python-standard-library-798d9ed946c0
NaN Values in the Python Standard Library | by Marcin Kozak | TDS Archive | Medium
October 7, 2023 - NaN means Not-a-Number. You can use it in numerical libraries — but also in the Python standard library.
🌐
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])