Home › Blog › Pandas interview questions with code-level answers

Pandas interview questions with code-level answers

Pandas interviews test whether you can manipulate tabular data fluently and efficiently in Python. Expect questions on Series and DataFrames, selecting with loc and iloc, handling missing values, groupby aggregations, merging and joining, reshaping with pivot and melt, time series, apply versus vectorised operations, memory use, and common pitfalls such as chained assignment. Live exercises usually ask you to clean and summarise a small dataset.

Fifteen common pandas interview questions

  1. What is the difference between a Series and a DataFrame?
  2. loc versus iloc?
  3. How do you find and handle missing values?
  4. How does groupby work? Show an aggregation with multiple functions.
  5. merge versus join versus concat?
  6. What join types does merge support?
  7. pivot versus pivot_table versus melt?
  8. How do you remove duplicates?
  9. Why is apply often slow, and what should you use instead?
  10. What is the SettingWithCopyWarning?
  11. How do you reduce a DataFrame's memory use?
  12. How do you work with dates and resample time series?
  13. How do you compute a rolling average?
  14. How do you read a file too large for memory?
  15. Find the top three products by revenue in each region.

Selection and cleaning

Grouping, merging and reshaping

TaskApproach
Aggregate by groupdf.groupby('region').agg(revenue=('amount', 'sum'), orders=('id', 'count'))
Group-wise transformdf.groupby('region')['amount'].transform('mean') keeps the original shape
SQL-style joinpd.merge(a, b, on='key', how='left')
Stack DataFramespd.concat([df1, df2], ignore_index=True)
Wide summarydf.pivot_table(index='region', columns='month', values='amount', aggfunc='sum')
Wide to longdf.melt(id_vars='id', var_name='metric', value_name='value')

Top three products per region: aggregate revenue by region and product, sort by revenue descending, then groupby('region').head(3). Interviewers like seeing validate='one_to_one' or indicator=True on merges, which catch unexpected duplicates.

Performance and pitfalls

Vectorised operations on whole columns run in optimised compiled code; apply with a Python function runs row by row and is far slower. Prefer built-in methods, numpy functions or np.where and np.select for conditional logic. Reduce memory by using category dtype for repeated strings and downcasting numeric types. SettingWithCopyWarning appears when you modify what may be a copy, often from chained indexing such as df[df.x > 0]['y'] = 1; use a single loc call or an explicit .copy(). For files too large for memory, read in chunks with chunksize, select only needed columns, or move to a tool built for larger data.

Time series

A live exercise to rehearse

Given an orders file with order_id, customer_id, order_date, amount and status, a typical sequence is: load it with dates parsed, drop exact duplicate rows, filter out cancelled orders, compute monthly revenue with resample or a groupby on the month, find each customer's first order date with groupby and min, and build a cohort table of revenue by first-order month. Narrate each step, check shapes and a few totals as you go, and mention what you'd do with missing amounts rather than silently dropping them.

Interviewers notice candidates who inspect the data before transforming it — df.info(), df.describe() and a quick look at value counts for categorical columns. It's the same habit that prevents silent mistakes in real analysis, and it takes thirty seconds.

pandas versus SQL and other tools

Expect a question on when you'd use pandas versus SQL. SQL is better when data lives in a database and can be filtered and aggregated there before moving; pandas shines for exploratory work, complex reshaping and feeding Python models. For data beyond memory, columnar formats such as Parquet, chunked processing or distributed tools are the next step. A sensible answer picks by data size, location and the task.

Practising

Interviewers follow up on the most specific thing you say, so rehearse the second question as well as the first. CoPilot Interview, a free AI interview assistant, runs pandas mock interviews with follow-ups and produces a report of likely next-round questions. Take a public dataset and answer five business questions with pandas, narrating each step. See also Python interview questions and data analyst interview questions.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.

Frequently asked questions

What is the difference between loc and iloc?

loc selects rows and columns by label or boolean mask; iloc selects by integer position.

Why is apply slow in pandas?

apply typically calls a Python function once per row or element, losing the speed of vectorised operations that run in optimised compiled code over whole columns.

merge or join?

merge is the general SQL-style join on columns or indexes. join is a convenience method that joins on the index by default. concat stacks DataFrames vertically or horizontally.

How do you fix SettingWithCopyWarning?

Avoid chained indexing. Use a single df.loc[row_selector, column] = value assignment, or take an explicit .copy() when you intend to work on a separate DataFrame.

Practise on real interview questions

Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.

Try a practice question