Filter Rows with Boolean Indexing
easypandas_explorationImplement filter_rows(df, max_age, name_starts, excl_surname).
df has columns 'name', 'surname', 'age'. Return only the rows where
all three conditions hold:
age <= max_agenamestarts with one of the prefixes inname_startssurname != excl_surname
Use boolean indexing — .query() is not allowed.
Keep the original index labels (no reset).
filter_rows(df, max_age=60, name_starts=("A","D"), excl_surname="Brown")
Constraints
- no query
Your solution
Edit filter_rows and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
Build a boolean mask for each condition separately, then combine with & (AND) and ~ (NOT).
Hint 2
df['name'].str.startswith(tuple_of_prefixes) returns True for names beginning with any of those prefixes.
Hint 3
df[mask] returns only the rows where mask is True.