Index.isna() function in pandas detects missing values i.e., NaN or None in a pandas.Index. It behaves identically to Index.isnull(), as both are aliases of each other. It returns a boolean array, where:
- True indicates a missing value.
- 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.isna())
Output[False True False False]
Syntax
Index.isna()
Parameters: This method does not take any parameters.
Returns: A NumPy boolean array indicating missing values. It returns True for missing values such as NaN or None and False for valid (non-missing) values.
Examples
Example 1: In this example, 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_values = idx[idx.isna()]
print(null_values)
OutputIndex([nan], dtype='float64')
Explanation: This filters out only the null (np.nan) values from the Index. The dtype becomes float64 because of the presence of nan.
Example 2: In this example, we verify that isna() and isnull() are functionally equivalent.
Python
import pandas as pd
import numpy as np
idx = pd.Index([None, 5, np.nan])
print(idx.isna() == idx.isnull())
Explanation: All elements return True, confirming isna() and isnull() are functionally identical.
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.isna().all())
Explanation: All values are missing, so isna().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.isna().any())
Explanation: At least one value (np.nan) is missing, so it returns True.
Related articles
Similar Reads
Python | Pandas Index.isna() Index.isna() function in pandas detects missing values i.e., NaN or None in a pandas.Index. It behaves identically to Index.isnull(), as both are aliases of each other. It returns a boolean array, where:True indicates a missing value.False indicates a valid (non-null) value.Example:Pythonimport pand
2 min read
Python | Pandas Index.isin() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.isin() function return a boolean array where the index values are in valu
2 min read
Python | Pandas Index.min() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.min() function returns the minimum value of the Index. The function works
2 min read
Python | Pandas Index.isnull() 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:Pythonimport pandas as pd import numpy as np idx = pd.Index(['a', None, 'c', 'd']) print(idx
2 min read
Python | Pandas Index.notna() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.Pandas Index.notna() function Detect existing (non-missing) values. Return a boolean sa
2 min read
Python | Pandas Index.is_unique Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.is_unique attribute return True if the underlying data in the given Index object is unique else it return False. Syntax: Index.is_uniq
2 min read