Use math.isnan:
>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
Answer from gimel on Stack OverflowNote.nkmk.me
note.nkmk.me › home › python
What is nan in Python (float('nan'), math.nan, np.nan) | note.nkmk.me
May 9, 2023 - See the following articles about how to remove and replace nan in NumPy and pandas. ... In Python, the float type includes nan, which can be created using float('nan').
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
Is np.nan a float?
Yes. np.nan is a floating-point value, so including it in a NumPy array of integers causes the array to use a floating-point dtype.
askpython.com
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
What does np.nan do?
np.nan is a floating-point NaN value used to mark an unavailable numeric entry. Use np.isnan to detect it in a NumPy array.
askpython.com
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
Why does np.nan not equal itself?
IEEE floating-point comparisons define NaN as unequal to every value, including another NaN. Use np.isnan or pandas isna instead of equality.
askpython.com
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
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.
DataCamp
datacamp.com › home › tutorials › python › python nan: 4 ways to check for missing values in python
Python NaN: 4 Ways to Check for Missing Values in Python | DataCamp
February 15, 2024 - Understanding the distinction between NaN and None is crucial in Python. NaN is a floating-point representation of "Not a Number," used primarily in numerical computations. None, on the other hand, is Python's object representing the absence of a value akin to null in other languages.
Call: +917738666252
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
RunxBuild
runxbuild.com › home › blog › python nan: the number that breaks equality and quietly spreads
Python NaN: The Number That Breaks Equality and Quietly Spreads
August 1, 2026 - Python NaN is a special IEEE 754 floating-point value for an undefined numeric result, and it must be tested with math.isnan rather than equality.
GeeksforGeeks
geeksforgeeks.org › python › difference-between-nan-and-none-in-python
Difference Between Nan and None in Python - GeeksforGeeks
July 23, 2025 - First we will be importing important libraries NumPy for mathematical computing and Pandas for data manipulation and then creating a Python dictionary and converting it into a Pandas DataFrame and then printing it. ... import pandas as pd import numpy as np # Create a DataFrame with some NaN values data = { 'A': [1, 2, np.nan, 4], 'B': [5, np.nan, np.nan, 8], 'C': [10, 11, 12, 13] } df = pd.DataFrame(data) # Printing the DataFrame print("DataFrame:") print(df)
W3Schools
w3schools.com › python › ref_math_nan.asp
Python math.nan Constant
The nan constant is equivalent to float('nan'). ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial