Python Pandas program to select the rows where the age is greater than a number

In this python pandas program, we will select the rows where the age is greater than a number using the pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dataframe using pd.DataFrame().
  3. Select the rows where the age is greater than a number using df[df[‘Age’] > 29].
  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,27,29,33]}
df = pd.DataFrame(d)
print(df)
print("Rows where age is greater than 29")
print(df[df['Age'] > 29])
				
			

Output :

				
					0   Sr.no.   Name  Age
0       1   Alex   30
1       2   John   27
2       3  Peter   29
3       4  Klaus   33
Rows where age is greater than 29
   Sr.no.   Name  Age
0       1   Alex   30
3       4  Klaus   33
				
			

print the selected rows from DataFrame

count the number of rows and columns in a DataFrame

Leave a Comment