Pandas Index.isnull()-Python
Last Updated : 24 Jun, 2025
Index.isnull() function in pandas detects missing values (NaN or None) in a pandas Index. It returns a boolean array where True indicates a missing value and False indicates a valid (non-null) value. Example:
Python import pandas as pd import numpy as np idx = pd.Index(['a', None, 'c', 'd']) print(idx.isnull())
Output[False True False False]
Explanation: Only the second value is None (null), so it's marked True. All other values are valid.
Syntax
Index.isnull()
Parameters: This method does not take any parameters.
Returns: A NumPy boolean array: True for missing values like NaN or None and False for valid ones.
Examples
Example 1: In this, we filter only the 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]) null_vals = idx[idx.isnull()] print(null_vals)
OutputIndex([nan], dtype='float64')
Explanation: This filters out the null (np.nan) from the Index. The dtype becomes float because of the presence of nan.
Example 2: In this, we verify that isnull() is the logical opposite of notnull().
Python import pandas as pd import numpy as np idx = pd.Index([None, 5, np.nan]) print(idx.isnull() == ~idx.notnull())
Explanation: Each element in the result is True, confirming both methods are logical opposites.
Example 3: In this, we check if all values in the Index are null using all().
Python import pandas as pd import numpy as np idx = pd.Index([None, np.nan]) print(idx.isnull().all())
Explanation: Every value in the Index is null, so isnull().all() returns True.
Example 4: In this, we check if any value in the Index is null using any().
Python import pandas as pd import numpy as np idx = pd.Index([1, 2, np.nan]) print(idx.isnull().any())
Explanation: Since there is at least one missing value (np.nan), the result is True.
Related articles: pandas