Pandas
pandas is an analyst's workhorse for tables too big for the head but small enough for memory. In an interview almost every practical task reduces to one of five operations: filter rows, group and aggregate, merge tables, compute a conditional aggregate, and look up a value at a point in time.
The main trap is not the syntax but the unit of analysis. "A customer's first order", "salary above the manager", "price as of a date" — in each task it matters which rows you compute over and what you compare against what. The map below runs from a simple filter to the as-of lookup.
Topic map
- Filtering — boolean masks,
isin, combining conditions, and picking a row withidxmin/idxmax. - Grouping —
groupbywithagg,sizeversuscount, and named aggregation. - Merging —
mergeon a key,left_on/right_on, self-merge, and thehowtypes. - Conditional aggregation — totals and a subset in one pass via helper columns.
- Point-in-time lookup — a value as of a date with a pre-change default.
Common traps
| Mistake | Consequence |
|---|---|
| Computing over all rows instead of first orders | An answer to a different question |
| Comparing to an average instead of the linked row | Wrong "more than the manager" logic |
| Forgetting parentheses around conditions in a boolean mask | ValueError from operator precedence |
| Filtering before aggregating, losing the totals | The all-rows counts and sums vanish |
| Taking the global latest instead of as of the date | The target date is ignored |
Concatenating instead of a key-based merge | Rows are not matched by key |
Interview relevance
Practical pandas checks whether you translate the wording into the right unit of analysis and know the idiomatic techniques. A strong candidate says it out loud — "I take each customer's first order via idxmin, then the share" — clarifying which rows they compute over first.
Typical checks:
- Boolean filtering and picking one row per group.
groupby+aggand thesize/countdifference.merge— keys, self-merge,how, and nulls.- Conditional aggregation in one pass and the as-of lookup.
Common wrong answer: computing a metric over the whole table when the question is about customers' first orders. The syntax is right, but the unit of analysis is wrong — and the result answers a different question.