Python Pandas program to print the names

In this python pandas program we will print the names who’s age is between 25-30 using the Pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dataframe using pd.DataFrame().
  3. Print the names who’s age is between 25-30 using df[df[‘Age’].between(25,30)].
  4. Print the output.
				
					import pandas as pd
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 between 25 and 30 (inclusive):")
print(df[df['Age'].between(25,30)])
				
			

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 between 25 and 30 (inclusive):
   Sr.no.   Name  Age
0       1   Alex   30
1       2   John   27
2       3  Peter   29
				
			

select the rows where age is missing

change the age of John to 24

Leave a Comment