Use math.isnan:

>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
Answer from gimel on Stack Overflow
🌐
Note.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').
People also ask

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.
🌐
Towards Data Science
towardsdatascience.com › home › data science › nan values in the python standard library
NaN Values in the Python Standard Library | Towards Data Science
October 7, 2023 - NaN means Not-a-Number. You can use it in numerical libraries - but also in the Python standard library.
🌐
Turing
turing.com › kb › nan-values-in-python
How to Check for NaN Values in Python?[With Examples]
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.
🌐
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.
🌐
Digis
digiscorp.com › python-check-if-value-is-nan-a-complete-overview
Python Check If Value Is NaN: A Complete Overview
September 7, 2026 - Despite its name, NaN is still represented as a floating-point value in Python rather than as a separate “missing data” type.
Find elsewhere
🌐
AskPython
askpython.com › python › examples › nan-in-numpy-and-pandas
Understanding np.nan in NumPy and Pandas - AskPython
September 30, 2026 - Keep the environment active while running the Python examples. The commands use the package releases installed when you create it. NumPy promotes this array to float64 because np.nan is a floating-point value and the other entries are integers.
🌐
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 - Here is what I had using np.nan from Numpy. ... 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.
🌐
Towards Data Science
towardsdatascience.com › home › data science › 5 methods to check for nan values in in python
5 Methods to Check for NaN values in in Python | Towards Data Science
February 23, 2021 - ... NaN stands for Not A Number and is one of the common ways to represent the missing value in the data. It is a special floating-point value and cannot be converted to any other type than float.
🌐
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.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › numpy tutorial › numpy nan
NumPy NaN | Working of NumPy NaN in Python with Examples
April 19, 2023 - In Python, NumPy with the latest version where nan is a value only for floating arrays only which stands for not a number and is a numeric data type which is used to represent an undefined value. In Python, NumPy defines NaN as a constant value.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Appdividend
appdividend.com › np-nan
Numpy.nan (np.nan) in Python
July 11, 2025 - The np.nan is a special floating-point constant defined in the NumPy library that represents "Not a Number" (NaN).
🌐
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)
🌐
Konfuzio
konfuzio.com › start › blog › python › nan python - how to handle nan values in python correctly
NaN Python - How to handle NaN values in Python correctly
May 24, 2025 - NaN (NaN), which stands for "Not a Number", is a special floating point value in Python (and many other programming languages), which is used to represent undefined or non-representable values, such as the result of 0/0 or the square root of ...
🌐
Better Programming
betterprogramming.pub › did-you-know-float-nan-and-float-inf-exist-in-python-5a3b1054f4ce
Did You Know Float(“NaN”) and Float(“inf”) Exist in Python? | by Görkem Arslan | Better Programming
February 2, 2022 - Since it is not a defined keyword in Python, you have to pass it to float in a string format (within quotes). ... One thing worth mentioning here "Nan" is case insensitive. So you can use any format below to create a "Nan" value.
🌐
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 »