Python Pandas program to select the missing rows

In this python pandas program, we will select the missing rows using pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dataframe using pd.DataFrame().
  3. Select the missing rows in the age column using df[df[‘Age’].isnull()].
  4. Print the output.
				
					import pandas as pd
import numpy as np
d = {'Sr.no.':[1,2,3,4],'Name':['Alex','John','Peter','Klaus'],'Age':[30,np.nan,29,np.nan]}
df = pd.DataFrame(d)
print(df)
print("Rows where age is missing:")
print(df[df['Age'].isnull()])
				
			

Output :

				
					0   Sr.no.   Name   Age
0       1   Alex  30.0
1       2   John   NaN
2       3  Peter  29.0
3       4  Klaus   NaN
Rows where age is missing:
   Sr.no.   Name  Age
1       2   John  NaN
3       4  Klaus  NaN
				
			

count the number of rows and columns in a DataFrame

print the names who’s age is between 25-30 using Pandas

Leave a Comment