Check and count Missing values in pandas python

isnull() is the function that is used to check missing values or null values in pandas python. With this function we can check and count Missing values in pandas python. Let’s see how to get

  • is there any missing values in dataframe as a whole
  • is there any missing values across each column
  • how many missing values across each column

Let’s first create the dataframe.

import pandas as pd
import numpy as np

#Create a DataFrame
df1 = {
    'Subject':['semester1','semester2','semester3','semester4','semester1',
               'semester2','semester3'],
   'Score':[62,47,np.nan,74,np.nan,77,85]}

df1 = pd.DataFrame(df1,columns=['Subject','Score'])
print(df1)

So the resultant dataframe will be

Check and count Missing values in pandas python 1

 

Let’s check is there any missing values in dataframe as a whole


'''' is any missing values in dataframe '''
df1.isnull()

output:

Check and count Missing values in pandas python 2

 

Let’s check is there any missing values across each column

''' is any missing values across columns'''
df1.isnull().any()

There is no missing value in subject column and there are missing values in Score column

output:

Check and count Missing values in pandas python 3

 

Let’s check how many missing values across each column


''' how many missing values across columns'''
df1.isnull().sum()

There is no missing value in subject column and there are 2 missing values in Score column

output:

Check and count Missing values in pandas python 4

 

Check and count Missing values in pandas python p                                                                                                                Check and count Missing values in pandas python n