Python Practice › Pandas Programs › Program 37

Ages between 25 and 30

EasyPandas Programs · 37 of 95

Write a pandas program to print rows where age is between 25 and 30.

Advertisement
Output
    name  age
0   Alex   30
1   John   27
2  Peter   29

Approach

  1. between(25, 30) includes both ends.

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "age": [30, 27, 29, 33]})print(df[df["age"].between(25, 30)])
Output
    name  age
0   Alex   30
1   John   27
2  Peter   29
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs