Python | Pandas Index.notnull()

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.notnull() function detect existing (non-missing) values. This function return a boolean same-sized object indicating if the values are not NA. Non-missing values get mapped to 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, get mapped to False values.

Syntax: Index.notnull()



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

Example #1: Use Index.notnull()() function to detect missing values in the given Index.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index(['Jan', '', 'Mar', None, 'May', 'Jun', 'Jul',
                         'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
  
# Print the Index
idx

chevron_right


Output :

Let’s find out all the non-missing values in the Index

filter_none

edit
close

play_arrow

link
brightness_4
code

# to find the non-missing values.
idx.notnull()

chevron_right


Output :

As we can see in the output, all the non-missing values has been mapped to True and all the missing values has been mapped to False. Notice the empty string has been mapped to True as an empty string is not considered to be a missing value.
 

Example #2: Use Index.notnull() function find out all the non-missing values in the Index.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index([22, 14, 8, 56, None, 21, None, 23])
  
# Print the Index
idx

chevron_right


Output :

Let’s find out all the non-missing values in the Index

filter_none

edit
close

play_arrow

link
brightness_4
code

# to find the non-missing values.
idx.notnull()

chevron_right


Output :

As we can see in the output, all the non-missing values have been mapped to True and all the missing values have been mapped to False.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.