Python Pandas program to detect and display missing values from a DataFrame

In this python pandas program, we will detect and display missing values from a DataFrame using the pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dataframe using pd.DataFrame().
  3. Detect and display missing values from a DataFrame using df.isna().
  4. It will show True if the value is missing 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(df.isna())
				
			

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
   Sr.no.   Name    Age
0   False  False  False
1   False  False   True
2   False  False  False
3   False  False   True
				
			

merge two Dataframes with different columns

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

Leave a Comment