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
W3Schools
w3schools.com › python › ref_math_nan.asp
Python math.nan Constant
Python Examples Python Compiler ... Python Interview Q&A Python Training ... The math.nan constant returns a floating-point nan (Not a Number) value....
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)
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.
W3Schools
w3schools.com › python › ref_math_isnan.asp
Python math.isnan() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... # Import math Library import math # Check whether some values are NaN or not print (math.isnan (56)) print (math.isnan (-45.34)) print (math.isnan (+45.34)) print (math.isnan (math.inf)) print (math.isnan (float("nan"))) print (math.isnan (float("inf"))) print (math.isnan (float("-inf"))) print (math.isnan (math.nan)) Try it Yourself »