pandas interview questions: answers checked against the docs
The data manipulation questions data analysts and scientists get, answered in plain words and checked against the pandas user guide.
pandas interviews cover Series and DataFrames, loc versus iloc, missing data, groupby with agg, transform and filter, merge, join and concat, Copy-on-Write (the default since pandas 3.0), vectorization versus apply, categorical data, pivot tables and melt, time series, large files and duplicates. Below are 12 questions; each answer lists the pandas documentation pages it was checked against.
Basic pandas interview questions
Basic1. What is the difference between a Series and a DataFrame?
A Series is a one-dimensional labeled array: values plus an index. A DataFrame is a two-dimensional table of columns that share one index, where each column is a Series and columns can have different types. Selecting one column of a DataFrame returns a Series; selecting a list of columns returns a DataFrame.
Checked against: pandas user guide: intro to data structures
Basic2. What is the difference between loc and iloc?
loc selects by label (index and column names) and also accepts boolean masks; iloc selects by integer position. A common follow-up: label slices with loc include both ends, while position slices with iloc exclude the end, like ordinary Python slices.
Python (pandas) snippet · illustrative, not run on this pagedf.loc["2024-01":"2024-03", ["revenue", "cost"]] # labels, both ends included
df.iloc[0:3, 1:3] # positions, end excluded
df.loc[df["status"] == "open", "title"] # boolean mask with locChecked against: pandas user guide: indexing and selecting data
Basic3. How do you handle missing data?
Find it with isna() and count it per column, then decide per column: drop rows or columns with dropna(), fill with fillna() (a constant, a group statistic, or forward fill for time series), or keep it and handle it downstream. Know the dtype effect: with NumPy-backed types, missing values turn an integer column into floats, while the nullable dtypes such as Int64 keep integers.
Python (pandas) snippet · illustrative, not run on this pagedf.isna().sum()
df["salary"] = df["salary"].fillna(df.groupby("role")["salary"].transform("median"))
df = df.dropna(subset=["candidate_id"])Checked against: pandas user guide: missing data
Intermediate pandas interview questions
Intermediate4. What do groupby with agg, transform and filter each return?
groupby splits the data into groups, applies a function and combines the results. agg reduces each group to summary values (one row per group). transform returns a result with the same index as the original, which is ideal for adding group statistics as a new column. filter keeps or drops whole groups based on a condition.
Python (pandas) snippet · illustrative, not run on this pagesummary = df.groupby("department").agg(avg_salary=("salary", "mean"), headcount=("id", "count"))
df["dept_avg"] = df.groupby("department")["salary"].transform("mean")
big_depts = df.groupby("department").filter(lambda g: len(g) >= 10)Checked against: pandas user guide: group by
Intermediate5. What is the difference between merge, join and concat?
merge performs SQL-style joins on columns or indexes (inner, left, right, outer, cross). join is a shortcut that joins on the index. concat stacks objects along an axis: rows on top of each other or columns side by side. Use validate in merge to catch unexpected duplicate keys, and indicator=True to see where each row came from.
Python (pandas) snippet · illustrative, not run on this pageorders.merge(customers, on="customer_id", how="left", validate="many_to_one")
pd.concat([jan, feb, mar], ignore_index=True)Checked against: pandas user guide: merge, join and concatenate
Intermediate6. What changed with Copy-on-Write in pandas 3.0?
Copy-on-Write is the default from pandas 3.0: any DataFrame or Series derived from another behaves as a copy, and data is only copied when one of them is modified. As a result, chained assignment such as df["a"][0] = 1 never updates df, and calling an inplace method on a selected column does not change the original either. Write the update in one step with loc. This replaces the old SettingWithCopyWarning situations.
Python (pandas) snippet · illustrative, not run on this pagedf.loc[df["status"] == "open", "priority"] = "high" # one step: updates df
df["name"] = df["name"].str.strip() # assign the result backChecked against: pandas user guide: migration guide for pandas 3.0
Intermediate7. Why avoid apply and loops, and what should you use instead?
Row-by-row Python code (iterrows, apply with a Python function) runs slowly because each row goes through the Python interpreter. Prefer vectorized operations on whole columns, built-in methods, NumPy functions, boolean masks and np.where or np.select for conditional logic. Reach for apply when no vectorized form exists.
Python (pandas) snippet · illustrative, not run on this pageimport numpy as np
df["band"] = np.select([df["salary"] < 50_000, df["salary"] < 100_000], ["low", "mid"], default="high")Checked against: pandas user guide: essential basic functionality
Intermediate8. When should you use the category dtype?
For columns with a limited, repeated set of values, such as state, department or status. Categories are stored once and each row holds a small code, which can save a lot of memory and speed up groupby. Categories can also have an order, such as low < medium < high, which enables sorting and comparisons.
Python (pandas) snippet · illustrative, not run on this pagedf["state"] = df["state"].astype("category")
df.memory_usage(deep=True)Checked against: pandas user guide: categorical data
Advanced pandas interview questions
Advanced9. What is the difference between pivot, pivot_table and melt?
pivot reshapes long data to wide and fails if an index and column pair appears more than once. pivot_table does the same but aggregates duplicates (mean by default, or any function you pass), like a spreadsheet pivot table. melt goes the other way, turning wide columns into long rows, which suits plotting and groupby.
Python (pandas) snippet · illustrative, not run on this pagewide = df.pivot_table(index="region", columns="quarter", values="revenue", aggfunc="sum", fill_value=0)
long = wide.reset_index().melt(id_vars="region", var_name="quarter", value_name="revenue")Checked against: pandas user guide: reshaping and pivot tables
Advanced10. How do you work with time series data?
Parse dates with to_datetime, set them as a DatetimeIndex, then use resample to change frequency (daily to monthly totals, for example) and rolling for moving windows that look back from each row. Time zones, missing periods and business days are common follow-up questions.
Python (pandas) snippet · illustrative, not run on this pagedf["date"] = pd.to_datetime(df["date"])
monthly = df.set_index("date")["revenue"].resample("MS").sum()
rolling_avg = monthly.rolling(window=3).mean()Checked against: pandas user guide: time series, pandas user guide: windowing operations
Advanced11. How do you handle a file that is too big for memory?
Load less: read only the columns you need with usecols, set compact dtypes up front (category, smaller integers), and process the file in chunks with chunksize, aggregating as you go. If the data is still too large, move the work to a database or a tool built for larger-than-memory data.
Python (pandas) snippet · illustrative, not run on this pagetotals = {}
for chunk in pd.read_csv("applications.csv", usecols=["role", "salary"], dtype={"role": "category"}, chunksize=100_000):
for role, s in chunk.groupby("role", observed=True)["salary"].sum().items():
totals[role] = totals.get(role, 0) + sChecked against: pandas user guide: IO tools, pandas user guide: scaling to large datasets
Advanced12. How do you find and remove duplicates?
duplicated() flags repeated rows (or repeated values in chosen columns) and drop_duplicates() removes them. keep decides which copy survives: the first (the default), the last, or none. Decide which columns define a duplicate, and sort first if you want, for example, to keep the latest record per customer.
Python (pandas) snippet · illustrative, not run on this pagelatest = (df.sort_values("updated_at")
.drop_duplicates(subset=["customer_id"], keep="last"))Checked against: pandas user guide: indexing and selecting data
How to practice with this page
- Solve each question on a small DataFrame you build yourself.
- Rewrite one loop or apply call as a vectorized expression.
- Practice explaining groupby results row by row.
- Check which pandas version a team uses: Copy-on-Write changed behavior in 3.0.
Related interview prep and tools
Core Python with real output.
Open →QuestionsData science interview questionsStatistics and modeling with runnable Python.
Open →QuestionsSpark and PySpark interview questionsWhen the data no longer fits in memory.
Open →QuestionsSQL interview questionsThe same operations in SQL.
Open →Free toolResume summary generatorDraft a summary for a Data Analyst role; the title is filled in, you add your experience.
Open →Free toolLinkedIn headline generatorWrite a headline for a Data Analyst search.
Open →Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.
Questions people ask
What pandas topics come up often in data interviews?
Were these snippets run?
Do these answers apply to older pandas versions?
How this page is built
TryHired wrote these questions and answers. Statements about the technology were checked against the official documentation pages listed below, saved when the page was built (2026-11-16). The code snippets are short illustrations and were not run on this page. The question list is general practice: it does not predict what a particular employer will ask.
- Interviewers ask different questions for different roles and levels.
- Answers are short explanations, not complete references.
- No pandas code was run on this page. The answers follow the pandas 3.1 documentation; older versions behave differently around Copy-on-Write.
- pandas user guide: essential basic functionality (read 2026-11-15)
- pandas user guide: categorical data (read 2026-11-15)
- pandas user guide: intro to data structures (read 2026-11-15)
- pandas user guide: group by (read 2026-11-15)
- pandas user guide: indexing and selecting data (read 2026-11-15)
- pandas user guide: IO tools (read 2026-11-15)
- pandas user guide: merge, join and concatenate (read 2026-11-15)
- pandas user guide: migration guide for pandas 3.0 (read 2026-11-15)
- pandas user guide: missing data (read 2026-11-15)
- pandas user guide: reshaping and pivot tables (read 2026-11-15)
- pandas user guide: scaling to large datasets (read 2026-11-15)
- pandas user guide: time series (read 2026-11-15)
- pandas user guide: windowing operations (read 2026-11-15)