Pandas — Ultimate Guide for Data Analysis | Data Analyst Interview
📊 Data Manipulation

Pandas — The Ultimate Guide for Data Analysis

The most tested Python library in every data analyst interview. Master DataFrames, groupby, merging, and pivot tables to handle any real-world dataset with confidence.

Core Concepts
What interviewers test in Pandas

These six areas cover 95% of Pandas questions asked at UK and Indian data analyst interviews in 2026.

1Series & DataFrame

The two core structures. A Series is a 1D labelled array; a DataFrame is a 2D table — like a SQL table or Excel sheet.

  • Creating from dict, list, CSV
  • Index vs columns
  • dtypes and memory usage

2Selecting & Filtering

loc vs iloc, boolean masks, query() — the most common follow-up after “load this CSV”. Get this wrong and interviews end early.

  • df.loc[] label-based selection
  • Boolean masks with & and |
  • isin() and between()

3GroupBy & Aggregation

Split-apply-combine — the Pandas equivalent of SQL GROUP BY. Tested in 90% of data analyst interviews.

  • Named aggregations (modern style)
  • transform vs apply
  • Multi-column groupby

4Merging & Joining

merge(), join(), concat() — handle multiple tables just like SQL joins. A frequent live-coding task.

  • inner, left, right, outer joins
  • on vs left_on / right_on
  • Handling duplicate key columns

5Missing Data

isna(), fillna(), dropna() — every real dataset has nulls. Interviewers test whether you treat them thoughtfully.

  • Detecting and counting nulls
  • Mean / median imputation
  • Forward fill for time series

6Pivot & Reshape

pivot_table(), melt(), stack/unstack — reshape long-to-wide and back. Standard in case study rounds.

  • pivot_table with aggfunc
  • melt() for unpivoting
  • crosstab for frequency tables
Interview Example 1
Top 5 customers by revenue

The classic groupby question. Named aggregations show you write modern, readable Pandas.

import pandas as pd
df = pd.read_csv(‘orders.csv’)
 
top_customers = (
  df.groupby(‘customer_id’)
    .agg(orders=(‘order_id’,‘count’), revenue=(‘amount’,‘sum’), avg_order=(‘amount’,‘mean’))
    .sort_values(‘revenue’, ascending=False).head(5)
)
print(top_customers)
Interview Example 2
Month-over-month revenue growth

Tests pivot_table, datetime parsing, and pct_change in one question.

df[‘order_date’] = pd.to_datetime(df[‘order_date’])
df[‘month’] = df[‘order_date’].dt.to_period(‘M’)
 
monthly = df.pivot_table(index=‘month’, values=‘amount’, aggfunc=‘sum’)
monthly[‘mom_growth_%’] = monthly[‘amount’].pct_change() * 100
print(monthly.round(2))
Interview Questions
Real Pandas questions asked in 2026

Actual questions with model answers — from interviews at top UK and Indian companies.

What is the difference between loc and iloc?
loc selects by label — index name or column name. iloc selects by integer position. loc includes the end of a slice; iloc excludes it. Use loc in production code because it survives index resets that silently break iloc.
When would you use apply() vs a vectorised method?
Vectorised methods (str.replace, dt.year, arithmetic operators) run in compiled C — always prefer them. apply() is a Python loop and much slower. Only reach for apply() when no vectorised alternative exists — interviewers watch for unnecessary apply() calls on numeric columns.
How do you handle missing data in production?
First understand why data is missing — random vs systematic. Then decide: drop rows if missingness is small; impute with mean/median for numbers, mode for categories, forward-fill for time series. Always document the strategy and report null % before and after treatment.
What is the difference between merge() and concat()?
merge() combines DataFrames on shared keys — like a SQL JOIN. concat() stacks DataFrames row- or column-wise without matching keys. Use merge for joining tables, concat for appending monthly files or stacking similar datasets.
How would you optimise a slow Pandas script?
Profile first with %timeit. Then: vectorise over apply; convert object columns to category dtype; chunk large CSVs with chunksize parameter; downcast numerics; use query() for complex boolean filters. Avoid iterrows() — it is the slowest way to loop a DataFrame.
Quick Reference
Pandas cheat sheet

The methods that appear again and again in interviews.

MethodPurpose
df.head(n) / tail(n)Inspect first or last n rows
df.info() / describe()Schema overview and summary stats
df.loc[] / df.iloc[]Label-based vs position-based selection
df.groupby().agg()Split-apply-combine aggregation
pd.merge(a, b, how, on)Join two DataFrames like SQL
pd.concat([a, b], axis)Stack DataFrames row- or column-wise
df.pivot_table()Wide-format aggregated summary
df.fillna() / dropna()Handle missing values
df.sort_values(col)Sort rows by column(s)
df.value_counts()Count unique categorical values
df.drop_duplicates()Remove duplicate rows
df.to_csv() / to_excel()Export to file

Ready to ace your Pandas interview?

Book a free 30-minute mock and get real Pandas problems with live expert feedback.

Book Free Pandas Session