Open In App

Pandas Index.notnull()-Python

Last Updated : 24 Jun, 2025
Suggest changes
Share
Like Article
Like
Report

Index.notnull() function in pandas detect non-missing (non-NaN/None) values within a pandas Index. It returns a boolean array where True indicates the element is valid (not null) and False indicates it is missing. Example:

Python
import pandas as pd import numpy as np idx = pd.Index([1, 2, np.nan, 4]) print(idx.notnull()) 

Output
[ True True False True] 

Explanation: It returns True for all values that are not missing (NaN) and False for the missing one.

Syntax

Index.notnull()

Parameters: This method does not take any parameters.

Returns: A NumPy array of boolean values, with True where values are not null and False where values are NaN or None.

Examples

Example 1: In this example, we check which values in the Index are not null.

Python
import pandas as pd idx = pd.Index(['a', None, 'c', 'd']) print(idx.notnull()) 

Output
[ True False True True] 

Explanation: Only the second element None is null. All other string values are valid, so they return True.

Example 2: In this example, we filter only the non-null values from the Index using boolean indexing.

Python
import pandas as pd import numpy as np idx = pd.Index([10, 20, np.nan, 40]) valid_idx = idx[idx.notnull()] print(valid_idx) 

Output
Index([10.0, 20.0, 40.0], dtype='float64') 

Explanation: This filters out the np.nan value and returns only the valid numbers. The result is Index([10.0, 20.0, 40.0], dtype='float64'), as the presence of np.nan promotes the dtype to float.

Example 3: In this, we compare notnull() with the inverse of isnull() to confirm they are logical opposites.

Python
import pandas as pd import numpy as np idx = pd.Index([None, 5, np.nan]) print(idx.notnull() == ~idx.isnull()) 

Output
[ True True True] 

Example 4: In this, we check if all values in the Index are non-null using all().

Python
import pandas as pd import numpy as np idx = pd.Index([1, 2, np.nan]) print(idx.notnull().all()) 

Output
False 

Explanation: This verifying that for every value, notnull() produces the exact opposite of isnull().

Example 5: In this example, we check if any value in the Index is non-null using any().

Python
import pandas as pd import numpy as np idx = pd.Index([None, np.nan]) print(idx.notnull().any()) 

Output
False 

Explanation: This returns False because both values are null, so no valid values are found.

Related article: pandas


Similar Reads