Data and reporting

7 Python Data Analyst Interview Questions

Practice seven analyst questions with worked reasoning on weighted averages, duplicate join matches, missing data, streaming, and validation.

Answer a data analyst interview question by saying what one row represents, describing the calculation, and naming one check that could catch a mistake. These seven practice questions cover the reasoning behind common Python and SQL tasks, from weighting an average to processing a file in chunks.

Why is the average of daily averages sometimes wrong?

Suppose day one has two delivery times with a mean of 10 minutes. Day two has eight deliveries with a mean of 20 minutes. The average of the two daily means is 15 minutes. The mean across deliveries is 18 minutes because the two days had different counts. Compute the total duration from the raw records or weight the daily means by the corresponding number of included deliveries.

Ask whether the interviewer wants the mean across days or across deliveries. Equal day weights answer the first question. Delivery counts supply the weights for the second. If daily means were rounded, recombining them introduces rounding error. Use the original totals and counts when available. Work through Python mean, median and weighted-mean examples.

Why did a left join produce more rows?

A left join retains every left row and adds right-side matches. If a customer appears three times on the right, a matching left row can appear three times in the result. Suppose an order table has one row per order and a customer history table has one row per address revision. Joining only on customer ID gives each order every matching address version unless a separate rule picks the appropriate revision.

Check uniqueness on the expected “one” side before the join. In pandas, the validate argument to merge can reject an unexpected cardinality. Then measure unmatched keys and row counts. For time-dependent reference data, agree on whether the intended match uses the address known at order time or the current address. Those questions have different answers.

What do you do with missing values?

First identify whether values are missing, invalid, suppressed, or genuinely zero. A blank delivery duration could mean that delivery is still open. Filling it with zero would make late entries appear faster. Keep the original status and make eligibility explicit. Show the count of excluded records, especially if missingness varies by depot or date.

If asked whether to impute, say what downstream task the imputed value would support. A visible “unknown” group can make a descriptive report more honest. A predictive model might need an imputation policy learned from training data. The interview prompt should clarify the purpose. Explain how you would compare the result under a reasonable alternative and how you would describe the uncertainty.

How would you calculate the three busiest categories?

Define “busiest.” If the input has one row per job and the goal is number of jobs, filter to the requested period, count eligible jobs by category, and sort by count descending. Add a deterministic tie-breaker or retain all categories tied at the boundary. Determine what to do about jobs that belong to multiple categories. A category count can legitimately add up to more than the number of jobs in that case.

For a small iterable of labels, collections.Counter is enough. For a table, use a grouped count in Python or SQL. Explain the difference between counting rows and counting non-null values in a column. Then check a group with a missing label, a repeated key and a tie so the output semantics are visible.

How would you handle a file bigger than memory?

Ask which calculation the file needs. A total by depot can be computed with a streaming loop that keeps one running total per depot. An exact median has different requirements because the middle depends on the order of all values. For a larger workflow, SQLite or a tool with appropriate out-of-core operations may help, depending on the operation and available storage.

Suppose a prompt asks for one mean duration from a file supplied in chunks. Keep each chunk’s total and number of observed values, then combine those across all chunks. This yields the same arithmetic definition as a global mean. A distinct customer count needs different state because a customer can appear in several chunks. Counting distinct values per chunk and adding them overcounts repeats that cross boundaries.

Include a check independent of performance. Run the same calculation on a small file one time in memory and another time in several chunks. Put a repeated key and a missing value on chunk boundaries. Compare both results with hand-calculated expectations. This helps separate improvements in processing from changes in the question being answered.

How would you explain the result to someone outside the team?

Give the outcome in their units and state the most important qualifier. For example, “Of the 80 deliveries with both times recorded, 12 took longer than an hour. We could not classify 5 additional deliveries.” If a manager asks whether one depot is doing worse, explain which depots can be compared on the available evidence. Offer the detail in a table so the main conclusion remains clear.

How do you know your report is correct?

Start with a handful of fixtures whose expected totals you can calculate without Python. Reconcile raw rows to excluded and included rows, compare before-and-after counts for joins, and test edge cases such as a group with no rows. Spot-check the records near time boundaries. Then run the process in a clean environment or notebook kernel using only the documented input.

Practice turning an ambiguous question into a clear one before coding. “How many orders finished last week?” contains at least two choices: which event counts as finished and where a reporting week starts. If you can make those choices explicit and defend one small calculation, you are showing analysis skill with or without a long code sample.

Give your reviewer a useful check for their follow-up. If they propose comparing two warehouses, ask whether both use the same time zone and update statuses the same way. Then pick a single record whose classification would change if an assumption were wrong and explain how you would verify it against the source.

Sources and further reading

Related reading

Browse Data and reporting · Explore project tutorials

Search PythonProjects.org