![]() |
VOOZH | about |
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.
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.
DataFrame.isna()
Series.isna()
Parameters: No parameters needed.
Returns: A boolean DataFrame or Series indicating where values are NaN.
Example:
Output:
Name Age
0 False False
1 False True
2 True False
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().
DataFrame.isnull()
Series.isnull()
Parameters: No parameters needed.
Returns: A boolean DataFrame or Series indicating where values are NaN.
Example:
Output:
Name Age
0 False False
1 False True
2 True False
Feature | isna() | isnull() |
|---|---|---|
Function Type | Primary function | Alias for |
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.
It often comes down to personal or team preference both work identically.
Once missing values are detected, you may want to handle them using methods such as: