Difference between isna() & isnull() in Pandas
Last Updated :
30 May, 2025
When you work with real-world data, it’s common to find missing or empty values. It’s important to handle these missing values carefully, especially when cleaning or exploring your data. Pandas, a popular Python tool for working with data, has two functions called isna() and isnull() that help you find these missing values. Even though their names are different, they actually do the same thing. This article will explain what these functions do, how they work, the small differences between them, and the best times to use each one.
What is isna() in Pandas?
The isna() function in Pandas is used to detect missing values in a DataFrame or Series. It returns a boolean object of the same shape, where True indicates the presence of a null (NaN) value and False indicates a non-null value.
Syntax
DataFrame.isna()
Series.isna()
Parameters: No parameters needed.
Returns: A boolean DataFrame or Series indicating where values are NaN.
Example:
Python
import pandas as pd
df = pd.DataFrame({
'Name': ['Alice', 'Bob', None],
'Age': [25, None, 30]
})
print(df.isna())
Output:
Name Age
0 False False
1 False True
2 True False
What is isnull() in Pandas?
The isnull() function works exactly like isna() it checks for NaN values in a DataFrame or Series and returns a boolean mask. It’s essentially an alias for isna().
Syntax
DataFrame.isnull()
Series.isnull()
Parameters: No parameters needed.
Returns: A boolean DataFrame or Series indicating where values are NaN
.
Example:
Python
Output:
Name Age
0 False False
1 False True
2 True False
Key Difference Between isna() and isnull()
Feature | isna() | isnull() |
---|
Function Type | Primary function | Alias for isna() |
---|
Source | Introduced to align with NumPy naming conventions | Original Pandas function |
---|
Use case | Preferred for consistency with NumPy | Commonly used for readability |
---|
Behavior | Identical | Identical |
---|
In essence, there is no difference in behavior. They are interchangeable and produce the same result.
When to Use isna() vs. isnull()?
- Use isna() if you want consistency with NumPy (np.isnan) or follow newer Pandas conventions.
- Use isnull() if you find it more intuitive or readable in your project.
It often comes down to personal or team preference both work identically.
How to Handle Missing Data Using isna() or isnull()
Once missing values are detected, you may want to handle them using methods such as:
1. Dropping rows with missing values
Python
2. Filling missing values
Python
df_filled = df.fillna(value={'Age': 0})
3. Counting missing values
Python
missing_counts = df.isna().sum()
print(missing_counts)