Identify the columns from the DataFrame which have at least one missing value

In this python pandas program, we will identify the columns from the DataFrame which have at least one missing value using the pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dataframe using pd.DataFrame().
  3. Identify the columns from the DataFrame which have at least one missing value using df.isna().any().
  4. It will print True in front of the column name if that column has any missing value or else False.
  5. Print the output.
				
					import pandas as pd
import numpy as np
df = pd.DataFrame({'Sr.no.':[1,2,3,4],
                   'Name':['Alex','John','Peter','Klaus'],
                   'Age':[30,np.nan,29,np.nan]})
print("Original Dataframe: \n",df)
print("Identify the columns which have at least one missing value:")
print(df.isna().any())
				
			

Output :

				
					Original Dataframe: 
    Sr.no.   Name   Age
0       1   Alex  30.0
1       2   John   NaN
2       3  Peter  29.0
3       4  Klaus   NaN
Identify the columns which have at least one missing value:
Sr.no.    False
Name      False
Age        True
dtype: bool
				
			

detect missing values from a  DataFrame

count the number of missing values in each column of a DataFrame

Leave a Comment