Data Science Interview Questions: Statistics, pandas, SQL

Data science interviews test three muscles: statistics intuition, pandas fluency, and SQL you can write without thinking. This Q&A covers the questions that actually get asked — each with the crisp answer and the trap underneath.

Statistics

1. Mean vs median vs mode — when is the mean misleading?

Answer: the mean is sensitive to outliers; the median isn't. "Average salary at this company is $200k" means little if one founder makes $2M — report the median. Use the mode for categorical data. Follow-up: "What would you report for a skewed distribution?" — median + IQR, or log-transform first.

2. Explain p-value without jargon

Answer: assuming there's no real effect, the p-value is the probability of seeing results at least this extreme by luck alone. p = 0.03 doesn't mean "97% chance the effect is real" — that's the classic misreading. It means: if nothing were going on, you'd see this 3% of the time. Follow-up: "p = 0.06 — ship it?" — the 0.05 line is convention, not physics; report the effect size and confidence interval instead of worshipping the threshold.

3. Correlation vs causation — how do you check?

Answer: correlation is symmetric and cheap; causation needs a mechanism or an experiment. In observational data, look for confounders (the third variable driving both), use A/B tests when possible, and never let a 0.9 correlation write your conclusion. The interview one-liner: "Ice cream sales correlate with drownings — the confounder is summer."

4. Bias vs variance — and what do you do about each?

Answer: bias = systematically wrong (underfit: model too simple); variance = unstable across samples (overfit: model memorizes noise). High bias → richer model, more features. High variance → more data, regularization, simpler model, cross-validation. The trade-off curve is the single most-drawn diagram in ML interviews — be ready to sketch it.

5. What does the Central Limit Theorem buy you?

Answer: sample means become approximately normal as n grows, regardless of the underlying distribution — which is why you can build confidence intervals and run t-tests on real-world messy data. The catch interviewers probe: it needs independent samples and a finite variance; n = 30 is folklore, not a theorem.

pandas

6. groupby-apply vs vectorization?

# slow: row-wise apply
df['total'] = df.apply(lambda r: r['a'] + r['b'], axis=1)

# fast: vectorized
df['total'] = df['a'] + df['b']

# grouped aggregation — the bread and butter
df.groupby('region')['sales'].agg(['mean', 'sum'])

Answer: vectorized ops run in C and are 10–100x faster than apply(axis=1). Reach for groupby + aggregations first; use apply only when the logic genuinely can't vectorize. Follow-up: "groupby is slow on 100M rows — now what?" — categorical dtypes, chunking, or Polars/Dask.

7. How do you handle missing data?

Answer: first ask why it's missing (MCAR vs systematic — missing income data is rarely random). Then: drop if tiny and random; impute with median/mode for quick baselines; model-based imputation or an explicit "missing" indicator when the missingness itself carries signal. Never silently fillna(0) — zero is a value, not an absence.

8. merge vs join vs concat?

Answer: merge = SQL-style join on columns (inner/left/right/outer via how); join = merge on the index; concat = stack frames vertically or side-by-side. The interview trap: "Your merge exploded from 1M to 50M rows — why?" — duplicate keys on both sides (many-to-many); validate with validate='m:1'.

SQL

9. Write the 2nd highest salary (and don't say LIMIT 1,1)

-- correct with ties handled:
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

-- general Nth: dense_rank
SELECT salary FROM (
  SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS r
  FROM employees
) t WHERE r = 2;

Answer: the subquery version is the classic; DENSE_RANK() generalizes to Nth and handles ties correctly (RANK() skips numbers on ties — know the difference).

10. GROUP BY vs WHERE vs HAVING?

Answer: WHERE filters rows before grouping; HAVING filters groups after aggregation. "Departments with average salary > 100k" needs HAVING — putting an aggregate in WHERE is the #1 SQL interview error.

11. Window functions in one minute

-- running total per region, plus rank within region:
SELECT region, month, sales,
       SUM(sales) OVER (PARTITION BY region ORDER BY month) AS running_total,
       RANK() OVER (PARTITION BY region ORDER BY sales DESC) AS sales_rank
FROM quarterly;

Answer: window functions compute across rows without collapsing them — ROW_NUMBER, RANK/DENSE_RANK, LAG/LEAD, running SUM. If you can write these fluently, you pass 80% of SQL rounds.

In this series

  1. Top 50 Python DSA Problems by Pattern (With Solutions) — two pointers to intervals.
  2. Data Science Interview Questions: Statistics, pandas, SQL (this post).
  3. Machine Learning Interview Questions — Distilled From 7 Tutorials — regression to deployment.

Full Python roadmap: Python Learning Roadmap 2026 — all 50 tutorials across 8 tracks.

Comments

Popular posts from this blog

Java Banking Finance Services and Insurance (BFSI) domain interview questions

JSP Servlet Interview Questions For Freshers Series 1

Java program to check even or odd number