30 Pandas Interview Questions and Answers for Data Analysts and Data Scientists
On this page
Short answer: Pandas interviews for data analyst and data scientist roles usually test: core objects (Series and DataFrame), selecting data (loc vs iloc, boolean filters), cleaning (missing values, duplicates, data types), aggregation (groupby, agg, pivot_table), combining data (merge, join, concat), dates, and performance (vectorisation over loops). Expect a live task such as “find the top 3 products by revenue in each month”. The 30 questions below cover each area with short code answers.
Key takeaways
- Master loc vs iloc, groupby and merge; they appear in almost every interview.
- Know how to handle missing values and data types.
- Prefer vectorised operations to loops and
apply. - Practise scenario questions on real CSV files.
Basics
1. What is Pandas?
An open-source Python library for working with tabular data, built on NumPy, providing the Series and DataFrame structures.
2. Series vs DataFrame?
A Series is a one-dimensional labelled array (one column); a DataFrame is a two-dimensional table of columns that can have different types.
3. How do you read a CSV and inspect it?
import pandas as pd
df = pd.read_csv('sales.csv')
df.head(); df.info(); df.describe(); df.shape
4. What is the index?
Row labels used for alignment and fast lookup. Reset it with df.reset_index(drop=True) or set one with df.set_index('id').
Selecting and filtering
5. loc vs iloc?
loc selects by labels (and the end label is included); iloc selects by integer position (end excluded).
df.loc[0:5, ['name', 'city']] # labels
df.iloc[0:5, 0:2] # positions
6. How do you filter rows with multiple conditions?
df[(df['city'] == 'Mumbai') & (df['sales'] > 1000)]
Use &, | and ~ with parentheses, not and/or.
7. How do you filter by a list of values?
df[df['city'].isin(['Mumbai', 'Pune'])]
8. What does query() do?
Filters with a string expression: df.query('sales > 1000 and city == "Mumbai"').
Cleaning data
9. How do you find and handle missing values?
df.isna().sum()
df['age'] = df['age'].fillna(df['age'].median())
df = df.dropna(subset=['email'])
10. How do you remove duplicates?
df = df.drop_duplicates(subset=['customer_id', 'order_id'], keep='first')
11. How do you change data types?
df['price'] = pd.to_numeric(df['price'], errors='coerce')
df['date'] = pd.to_datetime(df['date'])
df['city'] = df['city'].astype('category')
12. How do you rename columns?
df = df.rename(columns={'Cust Name': 'customer_name'})
13. How do you clean text columns?
df['city'] = df['city'].str.strip().str.title()
Aggregation
14. How does groupby work?
Split–apply–combine: split rows into groups, apply an aggregation, combine the results.
df.groupby('city')['sales'].sum()
15. Multiple aggregations?
df.groupby('city').agg(total=('sales', 'sum'), avg=('sales', 'mean'), orders=('order_id', 'nunique'))
16. agg vs transform?
agg returns one row per group; transform returns a result aligned to the original rows, useful for adding group-level columns.
df['city_avg'] = df.groupby('city')['sales'].transform('mean')
17. What is pivot_table?
pd.pivot_table(df, values='sales', index='city', columns='month', aggfunc='sum', fill_value=0)
18. value_counts?
Counts unique values: df['city'].value_counts(normalize=True) gives proportions.
Combining data
19. merge vs join vs concat?
| Method | Use |
|---|---|
merge |
SQL-style join on columns |
join |
Join on index (convenience method) |
concat |
Stack DataFrames vertically or horizontally |
20. Types of merge?
pd.merge(orders, customers, on='customer_id', how='left') # inner, left, right, outer
These mirror SQL joins; see SQL Joins Explained.
21. How do you check a merge didn’t duplicate rows?
Compare row counts before and after, or use validate='many_to_one' in merge.
Dates and time series
22. How do you extract date parts?
df['month'] = df['date'].dt.to_period('M')
df['weekday'] = df['date'].dt.day_name()
23. How do you resample time series?
df.set_index('date').resample('ME')['sales'].sum()
In recent Pandas versions, month-end is 'ME' (older versions used 'M').
24. Rolling averages?
df['sales_7d'] = df['sales'].rolling(7).mean()
Performance
25. apply vs vectorisation?
Vectorised operations (df['a'] * df['b']) run in optimised C code and are much faster than apply or Python loops. Use np.where or np.select for conditional columns.
26. How do you reduce memory usage?
Use smaller numeric types, category for repeated strings, and read only needed columns with usecols.
27. What is SettingWithCopyWarning?
A warning that you may be modifying a copy of a slice. Use .loc for assignment, or .copy() when you intend a separate DataFrame.
Scenario questions
28. Top 3 products by revenue in each month?
monthly = df.groupby(['month', 'product'], as_index=False)['revenue'].sum()
top3 = monthly.sort_values('revenue', ascending=False).groupby('month').head(3)
29. Each customer’s first purchase date?
first = df.groupby('customer_id')['date'].min().reset_index(name='first_purchase')
30. Month-over-month growth?
m = df.groupby('month')['revenue'].sum()
growth = m.pct_change() * 100
How to prepare
- Practise on public datasets (sales, HR, e-commerce)
- Solve each scenario in both Pandas and SQL; see SQL interview questions
- Review Python interview questions for data science
- Build a cleaning + analysis project for your portfolio
Frequently asked questions
Is Pandas enough for a data analyst job?
Pandas plus SQL, Excel and a BI tool such as Power BI is a strong combination for analyst roles.
Pandas or SQL for interviews?
Both. Many companies test SQL first and Pandas in a Python round.
Should I learn Polars instead?
Pandas remains the most widely used and most asked about; Polars is worth exploring after you know Pandas well.
Conclusion
To crack Pandas interview questions, master selection, cleaning, groupby, merge, dates and vectorisation, then practise scenario tasks until you can solve them quickly and explain your approach.
Learn Python and Pandas hands-on in our Python course.
Learn with Mehul Prajapati in Borivali West
At Mehul Prajapati’s institute, you get 100% practical, hands-on training by industry experts with a minimum of 5+ years of experience, plus job-oriented programmes with placement support. Weekday and weekend batches are available, with multiple 2-hour slots between 8 am and 6 pm.
Address: 12th Floor, 1214, Gold Crest Business Centre, LT Rd, Above Westside Showroom, Borivali West, Mumbai, Maharashtra 400092
Call: +91 99301 12627 / +91 96645 45072
Visit the centre or call us to choose the right course and batch and to know the current fee structure.