.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
All contributors
Looking to contribute?
- 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.