.isna()
Published Mar 29, 2023Updated May 6, 2023
Contribute to Docs
The .isna()
method checks whether the objects of a Dataframe or a Series contain missing or null values (NA, NaN)
and returns a new object with the same shape as the original but with boolean values True
or False
as the elements. True
indicates the presence of null or missing values and False
indicates otherwise. The original DataFrame object, used to call the method, remains unchanged.
Syntax
# Check for NA values.
df.isna()
Example
Here are some examples for using the .isna()
method on both DataFrame and Series objects:
Example 1: .isna()
with a DataFrame
import pandas as pd# Create a DataFrame with missing valuesdf = pd.DataFrame({'A': [1, 2, None, 4],'B': [5, None, 7, 8],'C': ['a', 'b', None, 'd']})# Check for missing values in the DataFramemissing_values = df.isna()print(missing_values)
The code above results in the following output:
A B C0 False False False1 False True False2 True False True3 False False False
Example 2: .isna()
with a Series
import pandas as pd# Create a Series with missing valuess = pd.Series([1, None, 3, None, 5])# Check for missing values in the Seriesmissing_values = s.isna()print(missing_values)
The code above results in the following output:
0 False1 True2 False3 True4 False
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pandas on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours