The notna() method in Pandas

In this exercise, we are using the datasource employeeswithna.csv. You can download the datasource and use for the transformation.

The notna() method is used to return a same sized boolean object indicating non-null values in the Series/DataFrame.

Syntax a) pandas.Series.notna()
b) pandas.DataFrame.notna()

Example: Load the Dataframe.

Python

import pandas as pd
mydata=pd.read_csv("employeeswithna.csv")
mydata 

The output of the above code is shown below:

The notna() method in Pandas

Let’s find the non-null values in the dataframe.

Python

mydata.notna()    

The output of the above code is shown below:

The notna() method in Pandas

Filter the non-null values Let’s filter the null values from the DataFrame.

Python

# Filter the non-null values from the DataFrame
boolean_gender=mydata["Gender"].notna()
mydata[boolean_gender]   

The output of the above code is shown below:

The notna() method in Pandas