The count() 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.count()
b) pandas.DataFrame.count()

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 count() method in Pandas

Let’s count the non-null values in each column of the dataframe.

Python

mydata.count()   

The output of the above code is shown below:

The count() method in Pandas