Filter Rows with Boolean Indexing

easypandas_exploration

Implement filter_rows(df, max_age, name_starts, excl_surname).

df has columns 'name', 'surname', 'age'. Return only the rows where all three conditions hold:

  1. age <= max_age
  2. name starts with one of the prefixes in name_starts
  3. surname != 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.

⌘/Ctrl + ↵

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.