Skip to the page

pandas for analysis · Scenario

Delivery times with gaps

The interviewer asks

You're asked for the average delivery time by city from a pandas DataFrame. About 20% of delivery_minutes values are missing. A teammate suggests fillna(0), or filling with the mean. What do you do?

Then

Follow-ups the interviewer asks next

  1. What do fillna(0) and filling with the mean each do to your answer?
  2. How do you find out why values are missing?
  3. The missing values are mostly from two cities. What does that change?
  4. Is there another source for delivery time?
  5. How do you report the result honestly?

The answer

What a strong answer covers

  • fillna(0) adds fake instant deliveries and drags the average down; filling with the mean keeps the average but shrinks the spread and hides the problem; mean() skips NaN, which is fine only if the missing rows are like the rest.
  • Looks for a pattern: df["delivery_minutes"].isna().groupby(df["city"]).mean(), and the same by platform, app version, payment type and status.
  • Not random here: cancelled orders (leave them out, don't fill them) and one rider-app version that doesn't send the delivered event in two cities, so those cities' averages rest on fewer, possibly different orders.
  • Uses another source if there is one (the time the customer's OTP was verified at handover), or reports those cities separately with their coverage.
  • Shows coverage next to each number ("based on 81% of orders") and asks engineering to fix the tracking.
  • pandas tools: isna, notna, dropna(subset=…), group-wise filling with transform only when imputation is justified.

The red pen

Common traps

Avoid:filling first and never asking why; dropping every row with a NaN in any column.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview