Python Practice › Pandas Programs › Program 34
Rows where age > 29
Write a pandas program to select the rows where age is greater than 29.
Output
name age 0 Alex 30 3 Klaus 33
Approach
- Boolean indexing.
Solution
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "age": [30, 27, 29, 33]})print(df[df["age"] > 29])Output
name age 0 Alex 30 3 Klaus 33
Learn the concept
New to this topic? Read the lesson, then come back.