Chapter 5 · 6 levels

Filtering and sorting

Pick rows by position and label, filter with boolean masks, combine conditions, and sort with tie-breakers on the Harbor & Pine tables.

Start

Most questions you’ll get as an analyst start with “only the…”: only marketplace orders, only completed orders from the app, only lighting under $200, only sessions that came from email. Then they end with “…the top ten”. Filtering and sorting are those two halves.

In pandas, filtering works through boolean masks: a column of True and False values, one per row, that says which rows to keep. Once that idea clicks, every filter looks the same, whether it has one condition or five.

This chapter also introduces .loc and .iloc, the two precise ways to select rows and columns together, and sort_values with proper tie-breaking so your top-N lists are stable. The boss level puts it all together on 40,000 website sessions.

Levels

  1. Rows by position, columns by name

    from Thomas Whitaker, Head of Merchandising

    loc, iloc, index, row selection

    Code Difficulty 2 of 5 Not started

  2. Only the marketplace orders

    from Megan Collins, Head of Sales

    boolean mask, filtering, comparison

    Code Difficulty 1 of 5 Not started

  3. Combine conditions with & and |

    from Daniel Brooks, Head of Operations

    boolean mask, and or not, isin, parentheses

    Code Difficulty 2 of 5 Not started

  4. The ten most expensive products

    from Thomas Whitaker, Head of Merchandising

    sort values, ascending, tie breaking, head, reset index

    Code Difficulty 2 of 5 Not started

  5. Lighting in a price band

    from Jordan Reyes, Head of Marketing

    between, str contains, filtering, sorting

    Code Difficulty 2 of 5 Not started

  6. Boss: who converts on the website?

    from Jordan Reyes, Head of Marketing

    boolean mask, mean of boolean, sort values, loc

    Boss · 3 steps Difficulty 3 of 5 Not started