Pandas interview questions for data analysts usually test five areas: selecting and filtering data with loc and iloc, cleaning missing values and duplicates, aggregating with groupby and pivot_table, combining tables with merge, and working with dates and group-wise calculations like rank and cumsum. Interviewers also ask about performance and common pitfalls such as SettingWithCopyWarning.
If a data analyst job description mentions Python, expect pandas. Some interviewers ask conceptual questions ('what is the difference between loc and iloc?'), others share a small dataset and ask you to write code live. Either way, they want to see that you can clean, reshape and summarise data without fighting the library.
This guide covers 18 pandas questions that come up often in analyst interviews, grouped by topic, each with a short model answer and code you can type from memory. For the wider question bank, including SQL and business questions, see our data analyst interview questions. All examples use a small orders table with columns order_id, customer, region, order_date and amount.
Basics: selecting, filtering and cleaning data
1. What is the difference between a Series and a DataFrame?
A Series is a one-dimensional labelled array, like a single column. A DataFrame is a two-dimensional table made of Series that share an index. Selecting df['amount'] returns a Series; df[['amount']] returns a DataFrame with one column.
2. What is the difference between loc and iloc?
loc selects by label and iloc selects by integer position. With loc, slices include the end label; with iloc, the end is excluded, like normal Python slicing. For example, df.loc[df['region'] == 'South', ['customer', 'amount']] filters rows and picks columns by name, while df.iloc[0:5, 0:3] returns the first five rows and first three columns.
3. How do you find and handle missing values?
Start by measuring: df.isna().sum() counts missing values per column. Then decide per column. You can drop rows with df.dropna(subset=['amount']), or fill them with a sensible value such as df['amount'] = df['amount'].fillna(df['amount'].median()). Say why you chose the approach: filling revenue with zero and filling it with a median tell very different stories.
4. How do you remove duplicate rows?
Use df.drop_duplicates(). Pass subset to define what counts as a duplicate and keep to choose which row survives, for example df.drop_duplicates(subset=['order_id'], keep='last'). Check first with df.duplicated(subset=['order_id']).sum() so you know how many rows you are removing.
5. How do you filter rows on multiple conditions?
Use boolean masks with & for and, | for or, and wrap each condition in brackets: df[(df['amount'] > 1000) & (df['region'] == 'South')]. The same filter with query reads more naturally: df.query("amount > 1000 and region == 'South'"). For membership, use df[df['region'].isin(['North', 'South'])].
Aggregation: groupby, transform and pivot tables
6. How do you calculate several aggregates per group?
Use groupby with named aggregation, which gives clean column names in one step:
summary = df.groupby('region').agg( total_sales=('amount', 'sum'), orders=('order_id', 'nunique'), avg_order=('amount', 'mean') )
7. What is the difference between agg and transform?
agg returns one row per group. transform returns a result the same length as the original DataFrame, so you can add it back as a column. A classic use is share of group total: df['region_share'] = df['amount'] / df.groupby('region')['amount'].transform('sum').
8. What is the difference between merge, join and concat?
merge combines tables on key columns, like a SQL join, with how set to 'inner', 'left', 'right' or 'outer'. join is a shortcut that joins on the index by default. concat stacks DataFrames vertically or side by side without matching keys. A strong follow-up answer is finding unmatched rows with indicator=True:
m = orders.merge(customers, on='customer_id', how='left', indicator=True) missing = m[m['_merge'] == 'left_only']
Also mention that you check row counts before and after a merge. If the count grows unexpectedly, the right table has duplicate keys. You can catch this early with validate='many_to_one'.
9. When would you use pivot_table instead of groupby?
Use pivot_table when you want a cross-tab layout, such as regions as rows and months as columns: df.pivot_table(index='region', columns='month', values='amount', aggfunc='sum', fill_value=0). groupby is better when you want a long table for further processing. pivot without the _table suffix only reshapes and fails if index and column pairs repeat.
Dates and group-wise calculations
10. How do you work with dates in pandas?
Convert first with df['order_date'] = pd.to_datetime(df['order_date']). Then use the dt accessor: df['order_date'].dt.month, .dt.day_name(), or df['order_date'].dt.to_period('M') to get a year-month period for monthly grouping. For time-based resampling, set the date as index and use df.resample('MS')['amount'].sum().
11. How do you get the top N rows per group?
Sort, then take the head of each group: df.sort_values('amount', ascending=False).groupby('region').head(3). This returns the three largest orders in every region. It is the pandas version of a SQL ROW_NUMBER filter and comes up very often.
12. How do you rank values within a group?
Use groupby with rank: df['rank_in_region'] = df.groupby('region')['amount'].rank(method='dense', ascending=False). Explain the method choice: 'dense' gives ties the same rank with no gaps, 'min' leaves gaps like SQL RANK, and 'first' breaks ties by order of appearance.
13. How do you calculate a running total per customer?
Sort by customer and date, then use cumsum inside groupby:
df = df.sort_values(['customer', 'order_date']) df['running_total'] = df.groupby('customer')['amount'].cumsum()
14. How do you calculate month-over-month growth?
Aggregate to one row per month, sort by month, then use pct_change. The worked example below walks through it step by step. For previous-period values without a percentage, use shift(1).
If the interviewer wants growth per region rather than overall, group by region and month first, then apply pct_change within each region: monthly_region.groupby('region')['amount'].pct_change(). Without that inner groupby, the first month of one region would be compared with the last month of the region before it, which is a common silent bug.
Performance and common pitfalls
15. Why should you avoid apply where possible?
apply runs a Python function row by row, which is slow on large data. Vectorised operations work on whole columns at once. Instead of df.apply(lambda r: r['amount'] 1.18, axis=1), write df['amount'] 1.18. For conditional logic, use np.where or np.select. Use apply when no vectorised option exists, and say so.
16. What is SettingWithCopyWarning and how do you avoid it?
It appears when you modify something that might be a copy of a slice, such as df[df['amount'] > 0]['flag'] = 1, so the change may not reach the original DataFrame. Use one loc call instead: df.loc[df['amount'] > 0, 'flag'] = 1. If you want a separate subset, create it with .copy(). Newer pandas versions move to Copy-on-Write, which changes this behaviour, but these habits stay correct.
17. How do you handle a CSV that is too large for memory?
Load only needed columns with usecols.
Set smaller types with dtype, and convert repeated text such as region to 'category'.
Read in pieces with chunksize and aggregate each chunk.
Check memory with df.info(memory_usage='deep').
For very large data, mention that you would push work to SQL or a tool like Spark.
18. How do you convert a wide table to a long one?
Use melt. If a table has one column per quarter, wide.melt(id_vars='region', var_name='quarter', value_name='sales') turns it into one row per region and quarter, which is much easier to group, filter and chart. The reverse is pivot or pivot_table.
Worked example: monthly revenue and growth
Here is a typical live task. Rahul, interviewing for a data analyst role at a product startup, was given six orders from September to November and asked for monthly revenue and month-over-month growth.
df['order_date'] = pd.to_datetime(df['order_date']) df['month'] = df['order_date'].dt.to_period('M') monthly = df.groupby('month', as_index=False)['amount'].sum() monthly['mom_pct'] = (monthly['amount'].pct_change() * 100).round(1)
month | amount | mom_pct |
|---|---|---|
2026-09 | 2050 | NaN |
2026-10 | 3730 | 82.0 |
2026-11 | 1500 | -59.8 |
groupby sorts by the month key by default, so pct_change compares each month with the previous one. The first month is NaN because there is nothing to compare it with. Point that out before the interviewer does, and mention that November is still a partial month, so the drop may not be real.
How do you explain your pandas code in the interview?
Interviewers care as much about your thinking as your syntax. Talk through the steps before you type, check the data shape as you go, and call out assumptions. A short script like this works well:
First I will check the types with df.info(), because order_date is probably a string. I will convert it to datetime and create a month period. Then I will group by month and sum amount, which gives one row per month in order. Finally I will use pct_change for growth. The first month will be NaN, and since November is not complete yet, I would flag that before anyone reads the drop as a real decline.
Interviewers also notice small habits that show you trust your data only after checking it. Mention a few of these as you work:
Look at df.head() and df.shape before and after each major step.
Confirm types with df.info(), especially dates and numbers stored as text.
Compare row counts before and after every merge.
Check for missing values in the columns you aggregate.
Sanity check one group total by hand, such as a single region.
If you forget an exact argument, say so and describe what you would look up. That is far better than going silent. Our technical interview tips cover more ways to think aloud, and if your role leans heavily on Python, review the Python developer questions too.
How should you practise these questions?
Build a small orders dataset yourself and solve each question without looking at the answer. Then explain your solution out loud in under a minute. Mock interviews score every answer, so you can see whether your explanations are clear. On interview day, the Interview Copilot for technical interviews gives you real-time transcription and answer drafts from your own resume. Follow each employer's interview rules: the goal is to express your own real skills clearly.
Want a preparation plan built around the exact job description you are applying for? Try InterviewPlan AI free with 5 live Copilot minutes and 100 AI credits, no card needed.
Frequently asked questions
Which pandas topics are most important for a data analyst interview?
Focus on filtering with loc and boolean masks, handling missing values and duplicates, groupby with named aggregation, merge and its join types, pivot_table, and date handling with to_datetime and the dt accessor. After that, practise group-wise calculations such as rank, cumsum, transform and top N per group, since these appear often in live coding tasks.
Do I need to memorise pandas syntax for interviews?
You should know the common methods well enough to write them without help: groupby, agg, merge, loc, fillna, sort_values and pivot_table. For less common arguments, it is fine to say what you would look up. Interviewers usually care more about a correct approach and clear reasoning than perfect recall of every parameter.
Is pandas or SQL more important for a data analyst role?
Most analyst roles expect SQL first, because data usually lives in databases. Pandas matters when the job description mentions Python, notebooks, automation or analysis beyond what SQL handles easily. Many interviewers ask the same question in both, such as top N per group, so learning the two side by side is efficient.
How do I prepare for a live pandas coding round?
Practise on a small dataset you create yourself, similar to an orders or sales table. Solve common tasks such as monthly totals, growth, ranking and joins without looking at notes. Get used to checking df.head(), df.info() and row counts as you go, and practise explaining each step aloud before you type it.
What is the difference between groupby and pivot_table in pandas?
groupby returns a long result with one row per group, which is ideal for further processing. pivot_table creates a spreadsheet-style cross-tab with one dimension as rows and another as columns, and it can fill missing combinations with fill_value. Under the hood both aggregate data, so choose based on the output shape you need.
