New · Cohort 3Engineering Analytics Cohort 3 goes live 25 July — only 30 seatsRegister Now
Data Engineering Interview Prep

Pandas Interview Questions: 16 Real Questions with Expert Answers

Sixteen pandas questions asked in real Indian data interviews — from loc vs iloc to Copy-on-Write and larger-than-RAM processing — with answers a strong candidate would actually give.

By Durgesh Yadav — Senior Data Engineer @ 7-Eleven · Updated 2026-07-25. Preparation guidance, not a hiring guarantee.

What are the most common pandas interview questions?

Pandas interviews focus on loc vs iloc indexing, merge/join/concat semantics, groupby with agg vs transform, vectorization over apply, handling missing data, and memory optimization with dtypes and categoricals. Expect a live coding round where you reshape data with pivot/melt, resample time series, and explain why a vectorized solution beats a row-wise loop.

Guide

What To Learn And How To Practice

What pandas rounds actually test

Across Indian data interviews — services, GCC, and product alike — pandas questions cluster around indexing, join semantics, and groupby. Most rounds are live: you share a screen, get a small dataset, and are judged on idiomatic vectorized code, not just correct output.

loc vs iloc and boolean masking are near-guaranteed openers
merge with duplicate keys and groupby transform separate practiced candidates from tutorial-level ones
Interviewers actively watch for chained-indexing mistakes and row-wise apply loops

Performance questions that separate seniors

At 3-6 years of experience, rounds shift from syntax to 'what happens at 10 million rows'. Expect memory questions (dtypes, categoricals), chunked processing of larger-than-RAM files, and honest tradeoff discussion about when to leave pandas for DuckDB, Polars, or the warehouse.

Know memory_usage(deep=True) behavior for object vs category vs pyarrow-backed strings
Be able to rewrite a row-wise apply as np.where/np.select on the spot
Have a chunksize plus partial-aggregation story ready for files that don't fit in RAM

How to prepare in one week

Pandas fluency is translation fluency: most questions are SQL problems in disguise. Drill the five core idioms daily — filtering, merging, groupby-transform, reshaping, resampling — and rehearse explaining your code aloud, because pandas rounds are as much talking as typing.

Redo 15-20 SQL practice questions in pandas to build the SQL-to-pandas mapping
Do one reshape task (pivot_table/melt) and one resample task every day
Practice without autocomplete — interview environments rarely have it

Question bank

16 interview questions with answers

Real questions from beginner to advanced, each with a concise model answer — practice them, then rehearse live in a mock interview.

EasyWhat is the difference between loc and iloc?

loc selects by label and iloc by integer position. The classic gotcha: loc slicing is inclusive of the end label (df.loc['a':'c'] includes 'c'), while iloc follows Python semantics and excludes the end (df.iloc[0:3] returns rows 0-2). loc also accepts boolean masks, which is the idiomatic way to filter with assignment: df.loc[mask, 'col'] = value.

EasyExplain the difference between merge, join, and concat.

pd.merge is a SQL-style join on one or more columns (or indexes) with how='inner'/'left'/'right'/'outer'. df.join is a convenience method that joins on the index by default, and pd.concat stacks DataFrames along an axis — axis=0 appends rows, axis=1 aligns on the index and adds columns. Worth adding: concat with mismatched columns produces a NaN-filled union unless you pass join='inner'.

EasyHow do you handle missing values in pandas?

Detect with isna()/notna(), drop with dropna(subset=..., how=...), fill with fillna() using a scalar, a per-column dict, or ffill/bfill, and use interpolate() for numeric gaps. A detail interviewers like: np.nan is a float, so an integer column with missing values silently becomes float64 unless you use nullable dtypes like Int64 with pd.NA.

EasyHow do you remove duplicate rows from a DataFrame?

df.drop_duplicates(subset=['col1','col2'], keep='first') deduplicates on chosen columns; keep='last' or keep=False change which rows survive, and df.duplicated() returns the boolean mask if you want to inspect duplicates first. For 'latest record per key', sort by timestamp then drop_duplicates(subset='key', keep='last').

EasyHow do you filter rows in a DataFrame?

Boolean masking is the standard: df[(df['salary'] > 500000) & (df['city'] == 'Bangalore')] — note the parentheses and & / | instead of and/or, because masks are element-wise arrays. df.query("salary > 500000 and city == 'Bangalore'") is a readable alternative, and isin() handles membership checks against a list of values.

MediumIn a groupby, what is the difference between agg, transform, and filter?

agg reduces each group to one row (df.groupby('dept')['sal'].agg(['mean','max'])); transform returns output aligned to the original DataFrame's shape, letting you broadcast group statistics back — df['dept_avg'] = df.groupby('dept')['sal'].transform('mean'); filter keeps or drops entire groups on a group-level condition. Transform is the expected answer to 'add each employee's deviation from department average without a join'.

MediumWhy is df.apply slow, and what should you use instead?

apply with axis=1 calls a Python function once per row, losing NumPy's C-level vectorization and paying interpreter overhead millions of times. Replace it with vectorized column arithmetic, np.where/np.select for conditionals, .str methods for strings, and map/replace for lookups. A typical result: a row-wise apply taking seconds on 1M rows drops to milliseconds as np.where(df['a'] > df['b'], 'x', 'y').

MediumWhat causes SettingWithCopyWarning and how do you avoid it?

It appears with chained indexing like df[df['x'] > 0]['y'] = 1, where pandas cannot guarantee whether you are writing to a view or a temporary copy — the assignment may silently do nothing. The fix is a single .loc call: df.loc[df['x'] > 0, 'y'] = 1. Copy-on-Write in pandas 2.x (default in 3.0) removes the ambiguity entirely: chained assignment simply never modifies the original.

MediumCompare pivot, pivot_table, and melt.

pivot reshapes long to wide but raises ValueError if an index/column pair has duplicates; pivot_table handles duplicates by aggregating them (aggfunc='mean' by default, with margins=True for totals). melt is the reverse — it unpivots wide columns into long id_vars/value_vars format, which is what you want before a groupby. Also know stack/unstack for MultiIndex-based reshaping.

MediumHow do you reduce a DataFrame's memory footprint?

Measure with df.memory_usage(deep=True), then downcast numerics (astype('int32'), pd.to_numeric(downcast=...)), convert low-cardinality strings to category — a city column with 50 unique values over 10M rows can shrink 10-20x — and pass dtype= and usecols= to read_csv so waste never loads at all. In pandas 2.x, the pyarrow-backed string dtype is far lighter than object.

MediumHow does resample work, and how is it different from rolling?

resample is a time-based groupby over a DatetimeIndex: df.resample('D')['sales'].sum() buckets rows into fixed calendar bins (D, W, ME, 15min) and aggregates each bin, changing the output frequency. rolling computes a sliding-window statistic over consecutive rows or a time offset (rolling('7D').mean()) while keeping the original frequency. asfreq changes frequency without aggregating — it only selects and fills, which is why asfreq('D') on sparse data introduces NaNs.

MediumWhat can go wrong in a pandas merge, and how do you defend against it?

Duplicate keys on either side cause a many-to-many explosion — a 1M-row merge can silently become 50M rows. Guard with validate='one_to_many' (raises MergeError on violation), use indicator=True to audit left_only/right_only rows after outer joins, and set suffixes explicitly so colliding columns don't become ambiguous _x/_y. Also verify key dtypes match — merging int64 keys against object keys matches nothing.

HardYou must process a 20 GB CSV on an 8 GB RAM machine. Walk me through it.

First cut columns and types at read time — read_csv(usecols=..., dtype={...}, parse_dates=[...]) often shrinks the working set 5-10x. If it still doesn't fit, stream with chunksize=1_000_000, aggregate each chunk, and combine partial results, which works for any distributive computation like sums, counts, or groupby partials. For repeated access, convert once to partitioned Parquet — and be honest that beyond a point the right tool is DuckDB, Polars, or Spark rather than pandas.

HardExplain Copy-on-Write in pandas 2.x and the view-vs-copy problem it solves.

Historically, whether indexing returned a view or a copy was unpredictable — it depended on internal block layout — which made chained assignment treacherous and forced SettingWithCopyWarning to exist. With CoW (pd.options.mode.copy_on_write = True; default in pandas 3.0), every derived object behaves as an independent copy, but data is only physically copied when you actually write, giving copy semantics at near-view performance. Practically: chained assignment never mutates the parent, and defensive .copy() calls mostly disappear.

HardHow would you join two time series whose timestamps don't match exactly?

pd.merge_asof performs an ordered nearest-key join: for each left row it picks the latest right-side row at or before its timestamp (direction='backward' by default), with tolerance= to cap the allowed gap and by= for per-key alignment such as symbol-wise quotes-to-trades matching. Both inputs must be sorted on the join key. It is the standard answer for trades vs quotes, sensor readings vs events, or attaching the most recent FX rate to transactions.

HardGet the latest record per user from a 100M-row events table — compare approaches.

The fastest pandas idiom is sort_values('ts').drop_duplicates('user_id', keep='last') — one sort plus a linear pass. df.loc[df.groupby('user_id')['ts'].idxmax()] reads cleaner but computes an index per group and is slower on high-cardinality keys. At 100M rows, also say you would push it to the warehouse with ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY ts DESC) and pull only the result — interviewers reward knowing when not to use pandas.

FAQ

Common Questions

How much pandas is asked in data engineer vs data analyst interviews?

Both get loc/iloc, merge, and groupby. Analyst rounds go deeper on reshaping, EDA, and plotting-adjacent tasks, while data engineer rounds pair pandas with SQL and push scale questions — memory tuning, chunked processing, and when to hand off to Spark or the warehouse.

Which pandas version should I prepare on?

Prepare on pandas 2.x. Copy-on-Write, pyarrow-backed dtypes, and the ME/YE frequency alias renames all come up in current interviews. Mentioning Copy-on-Write when asked about SettingWithCopyWarning immediately signals you are up to date.

Are documentation lookups allowed during pandas coding rounds?

Most Indian companies allow checking exact function signatures but not searching for full solutions. Core idioms — masking, merge, groupby-agg-transform, pivot_table — must come from muscle memory. Practicing in a plain editor without autocomplete is the safest preparation.

Should I also prepare Polars, or is pandas enough?

Pandas remains the default screening tool in India across services and GCCs. Polars is a bonus signal at product companies and data-platform teams; one honest sentence on its lazy evaluation and multi-threaded engine is usually enough, as depth is rarely tested yet.

Next Step

Turn The Guide Into Practice

Use PrepNPlaced tools to turn this learning path into resume proof, targeted practice, and interview-ready explanations.

Practice AI Mock Interview