NumPy & pandas interview questions

7 questions across 4 sections, in the order you would learn them. Every answer here is one that works — but an answer you have read is not an answer you can give, so use Test yourself and say it out loud first.

If this comes up in an interview

Why is vectorised NumPy faster than a Python loop?

The loop executes in the Python interpreter with per-element overhead, while the vectorised operation runs in compiled code over contiguous memory, often using multiple values per instruction. The difference is typically one to two orders of magnitude.

What does SettingWithCopyWarning mean?

You may be assigning to a copy rather than the original DataFrame, so the change silently does nothing. It usually follows a filter, and using .loc for conditional assignment avoids both the warning and the bug.

How would you handle missing values?

First find out whether missingness is informative, and if so record it as a feature before imputing. Then drop rows missing something essential, and impute the rest with a median or a model, fitted inside the training fold to avoid leakage.

Memory, views and larger-than-memory data

Read the section that teaches this

If this comes up in an interview

What is the difference between a view and a copy in NumPy?

A view shares memory with the original array, so modifying it changes the original; slicing usually returns a view. A copy is independent. Confusing them causes silent modifications.

How do you reduce the memory a DataFrame uses?

Choose smaller numeric types where the range allows, convert repeated strings to categorical, and read only the columns you need from a columnar format.

If this comes up in an interview

After a join, your total revenue doubled. What happened?

The right-hand table probably had duplicate keys, so each left row matched several right rows and was repeated. Check key uniqueness before joining, use validate to enforce the expected relationship, and compare row counts before and after.

Then they push further

How would you find the duplicates?

Group the right table by the join key and count, or use duplicated on the key column, and inspect those rows. Often it is a history table where each change adds a row, and you need the latest one per key.

What gets marked up. Marked up for naming duplicate keys immediately and for a preventive habit such as validate.

When pandas is slow: vectorising, Polars and DuckDB

Read the section that teaches this

If this comes up in an interview

A pandas job on a 20 GB CSV runs out of memory. What are your options?

Read only needed columns with compact dtypes, process in chunks, convert to Parquet, or use a tool that streams and parallelises such as Polars in lazy mode or DuckDB, which can query files larger than memory. Move to a distributed engine only if a single machine truly cannot cope.

These are the questions for one topic. The whole question bank covers every topic on the site.