51 Python Data Science Interview Questions and Answers (2026)

Most python data science interview questions fall into five groups: core Python for data work, NumPy, pandas, statistics and the machine learning workflow, followed by a live coding round on a messy DataFrame. Below are 52 of them with short answers and real output.

Here’s a warm-up that catches a lot of candidates. NumPy and pandas disagree about the same three numbers, because pandas skips NaN by default:

import numpy as np
import pandas as pd

s = pd.Series([3.0, np.nan, 5.0])
print(np.mean(s.to_numpy()), s.mean())   # nan 4.0

I ran the code on Python 3.12.5 with pandas 3.0.6, NumPy 2.5.3, scikit-learn 1.9.1 and SciPy 1.18.1, and the output blocks are pasted from those runs.

If you’re going for an analyst role, the first four sections matter most. For data scientist and ML roles, you’ll want extra time on the machine learning and coding sections.

Table of Contents:

Python basics interview questions for data science

1. Why is Python the default language for data science?

It’s readable, and the heavy math runs in compiled C under NumPy, pandas and scikit-learn, so you iterate fast without giving up speed. I compare the main tools in the best Python libraries for data science.

2. When do you use a list, tuple, set or dict?

You’d use a list for an ordered, changeable sequence, a tuple for a fixed record, a set for fast membership tests, and a dict for lookups by key.

3. What are list comprehensions and generators, and why do they matter for data?

A comprehension builds a whole list in one readable line. A generator expression uses parentheses and yields values one at a time, so its memory cost doesn’t grow with the data. See list comprehension in Python for the syntax:

import sys

prices = [19.99, 5.49, 120.00, 42.50]
with_tax = [round(p * 1.0825, 2) for p in prices]          # list comprehension
print([f"${p:.2f}" for p in with_tax], [p for p in prices if p > 20])

print("list of 1M values:", sys.getsizeof([n * 1.0825 for n in range(1_000_000)]), "bytes")
print("generator of 1M:  ", sys.getsizeof(n * 1.0825 for n in range(1_000_000)), "bytes")

Output:

['$21.64', '$5.94', '$129.90', '$46.01'] [120.0, 42.5]
list of 1M values: 8448728 bytes
generator of 1M:   200 bytes

The list of a million floats takes about 8.4 MB, while the generator object is 200 bytes. That’s why I stream big files through generators instead of loading them whole.

4. What is a lambda function, and where do data scientists use it?

A lambda is a one-expression anonymous function, like lambda x: x * 1.0825. You’ll see it in sorted(key=...), .assign() and .apply(). Examples on DataFrames are in using a lambda function on a pandas DataFrame.

5. How do you load a CSV that’s too big for memory?

Read only the columns you need with usecols, set compact dtypes, and process it in pieces with chunksize. If it still doesn’t fit, you can move to Parquet with DuckDB or Polars.

6. How do you check for None and NaN in Python?

Use x is None for None. NaN never equals itself, so x == float('nan') is always False; use math.isnan(), np.isnan() or pd.isna(), which catches both. More detail is in checking whether a number is NaN in Python.

7. How do you turn nested JSON into a DataFrame?

Use pd.json_normalize(): it flattens nested keys into columns like address.state, and record_path= expands nested lists into rows. Parsing the raw text first is covered in working with JSON data in Python.

NumPy interview questions for data science

Interviewers use NumPy to see whether you think in arrays instead of loops. For a deeper NumPy-only set, go to NumPy interview questions and answers.

8. Why are NumPy arrays faster than Python lists?

An array stores one data type in contiguous memory, and operations run as vectorized C loops. A list stores pointers to separate Python objects, so you pay a type check per element.

9. What is broadcasting?

Broadcasting lets NumPy combine arrays of different shapes without copying data. Shapes are compared from the right; each dimension must match or be 1. Here a (3,) discount row stretches across a (2, 3) price table:

import numpy as np
np.set_printoptions(precision=2, floatmode="fixed")

prices = np.array([[19.99, 5.49, 120.00],     # rows: Jan and Feb 2026
                   [21.50, 5.99, 115.00]])    # columns: three products, USD
print(prices.shape, prices.dtype)
print(np.where(prices > 20, "high", "low"))
print(prices * np.array([0.90, 1.00, 0.80]))  # broadcasting (2, 3) * (3,)
print("mean per product (axis=0):", prices.mean(axis=0))
print("total per month (axis=1): ", prices.sum(axis=1))

col = prices[:, 0]            # basic slice -> view
col[0] = 0.0
print("slice is a view:", prices[0, 0], np.shares_memory(col, prices))
big = prices[prices > 100]    # boolean mask -> copy
big[:] = 0.0
print("mask is a copy: ", prices.max())

a = np.array([3.0, np.nan, 5.0])
print(a.mean(), np.nanmean(a), np.nan == np.nan)

Output:

(2, 3) float64
[['low' 'low' 'high']
 ['high' 'low' 'high']]
[[17.99  5.49 96.00]
 [19.35  5.99 92.00]]
mean per product (axis=0): [ 20.74   5.74 117.50]
total per month (axis=1):  [145.48 142.49]
slice is a view: 0.0 True
mask is a copy:  120.0
nan 4.0 False
Command Prompt output of NumPy broadcasting, axis means, view versus copy and NaN handling for a data science interview
The discount row is applied to both months, the slice edit changes the original array, and the masked copy leaves it alone.