Skip to content

Python Interview Questions for Data Science

6 Python questions with answers for data science roles. Tick what you have solved to track your progress.

Sheet progressStart practicing
01

Pandas: find the top 3 products by revenue in each region.

Show answer
(df.assign(rev=df.price * df.qty) .groupby(['region', 'product'])['rev'].sum() .reset_index() .sort_values('rev', ascending=False) .groupby('region').head(3))
03

What is the difference between list, tuple, set and dict in Python?

Show answer
List: ordered and mutable. Tuple: ordered and immutable (hashable, slightly faster). Set: unordered, unique items, fast membership checks. Dict: key–value pairs with fast lookup by key.
04

What are *args and **kwargs?

Show answer
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. They make function signatures flexible and are common in wrappers and decorators.
05

Pandas: merge vs join vs concat?

Show answer
merge joins on columns, SQL-style (how='inner', 'left', ...). join joins on the index. concat stacks DataFrames along rows or columns.
06

How do you handle missing values?

Show answer
First understand why data is missing. Then drop rows or columns with too many nulls, impute with mean/median/mode or a model (KNN), add a 'was_missing' flag, and fit imputers on training data only.