Python | Pandas Index.notna ()

Index.notna() Pandas Index.notna() Detects existing (not missing) values. Returns a Boolean of the same size indicating that the values ​​are not NA. Values ​​not missing are displayed as True. Characters such as empty strings “or numpy.inf are not considered NA values ​​(unless you set pandas.options.mode.use_inf_as_na = True). NA values ​​such as None or numpy.NaN are mapped to false values.

Syntax: Index.notna ()

Parameters: Doesn`t take any parameter.

Returns: numpy.ndarray: Boolean array to indicate which entries are not NA.

Example # 1: Use Index.notna () to find all non-missing values ​​in Index.

# import pandas as pd

import pandas as pd

 
# Create index

idx = pd.Index ([ ` Labrador` , None , ` Beagle` , `Mastiff` ,

`Lhasa` , None , `Husky` , `Beagle` ])

# Print index
idx

Output:

Now we check for missing values ​​in the index.

 

# checks for non-missing values.
idx.notna ()

Output:

The function returned an array object of the same size as the index.  True means no index mark is missing, and False indicates no index mark.

Example # 2: Use Index.notna () to check for missing labels in the Datetime Indexe.

# import pandas as pd

import pandas as pd

 
# Create date and time index

idx = pd.DatetimeIndex ([pd.Timestamp ( `2015-02-11` ), 

None , pd.Timestamp (``), pd.NaT])

  
# Print date and time index
idx

Output:

Now we will check if there are tags in the Datetime index.

# check if the past Datetime has passed
# Index marks are missing or not.
idx.notna ()

Output:

As we can see from the output, the function returned an array object of the same size as the Datetime index.  True means no index mark is missing, and False indicates no index mark.