Use math.isnan:

>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
Answer from gimel on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_math_isnan.asp
Python math.isnan() Method
The math.isnan() method checks whether a value is NaN (Not a Number), or not.
🌐
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 - Let's explore four practical methods to check for NaN values in Python, continuing with the engaging examples we've already used. As we saw earlier, NumPy provides a straightforward approach to identifying NaN values in both single values and arrays, which is essential for numerical data analysis. import numpy as np # Checking a single value print(np.isnan(np.nan)) # Output: True # Checking an array my_array = np.array([1, 5, np.nan]) print(np.isnan(my_array)) # Output: [False False True]Powered by
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.1 Manual
numpy.isnan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'isnan'>#
🌐
Digis
digiscorp.com › python-check-if-value-is-nan-a-complete-overview
Python Check If Value Is NaN: A Complete Overview
September 7, 2026 - For an individual numeric value in standard Python code, math.isnan() is usually the clearest option.
🌐
Turing
turing.com › kb › nan-values-in-python
How to Check for NaN Values in Python?[With Examples]
The math module in Python provides the isnan() function, which can be used to check if a value is NaN. This method works only with floating-point values.
🌐
Codecademy
codecademy.com › docs › python › math module › math.isnan()
Python | Math Module | math.isnan() | Codecademy
September 4, 2024 - In Python, the math.isnan() function returns True if the given value is NaN (not a number) and False if the value is a number.
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-for-nan-values-in-python
Check For NaN Values in Python - GeeksforGeeks
July 23, 2025 - NaN values are commonly encountered in data science and numerical computing when working with datasets that contain missing, undefined, or invalid values. The numpy.isnan() function is a simple way to check for NaN values in a NumPy array.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python-math-library-isnan-method
Python math library | isnan() method | GeeksforGeeks
February 20, 2023 - Syntax : math.isnan(x) Parameters : x [Required] : It is any valid python data type or any number. Returns: Return type is boolean.
🌐
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 - Convert between bool (True/False) and other types in Python · As you can see with bool(), nan is evaluated as True. ... Use math.isnan() or np.isnan().
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.isnan.html
numpy.isnan — NumPy v2.5 Manual
numpy.isnan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'isnan'>#
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-library-isnan-method
Python math library | isnan() method - GeeksforGeeks
February 20, 2023 - Syntax : math.isnan(x) Parameters : x [Required] : It is any valid python data type or any number. Returns: Return type is boolean.
🌐
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 - Learn this step by step with the interactive AI and Data Scientist roadmap. isna() in pandas library can be used to check if the value is null/NaN. It will return True if the value is NaN/null.
🌐
Tutorial Gateway
tutorialgateway.org › python-isnan
Python isnan
August 10, 2026 - The Python isnan function is one of the Mathematical functions used to check whether the given value is a valid number or not.
🌐
Educative
educative.io › answers › what-is-numpyisnan-in-python
What is numpy.isnan() in Python?
Python’s numpy.isnan() tests if an element is · NaN · Not a Number or not. It tests an array element-wise and returns Boolean values.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-isnan-python
numpy.isnan() in Python - GeeksforGeeks
March 8, 2024 - numpy.isnan() in Python · Last Updated : 08 Mar, 2024 · Comments · Improve · Suggest changes · Like Article · Like · Report · The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-isnan-python
numpy.isnan() in Python - GeeksforGeeks
March 8, 2024 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 8 Mar, 2024 · The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array.
🌐
Index.dev
index.dev › blog › check-for-nan-values-in-python
4 Easy Ways to Check for NaN Values in Python (+Examples)
The np.isnan() function returns a boolean array indicating which elements in the input array are NaN.