InterviewStack.io LogoInterviewStack.io

Pandas Data Manipulation and Analysis Questions

Data manipulation and analysis using the Pandas library: reading data from CSV or SQL sources, selecting and filtering rows and columns, boolean indexing, iloc and loc usage, groupby aggregations, merging and concatenating DataFrames, handling missing values with dropna and fillna, applying transformations via apply and vectorized operations, reshaping with pivot and melt, and performance considerations for large DataFrames. Includes converting SQL style logic into Pandas workflows for exploratory data analysis and feature engineering.

HardTechnical
59 practiced
At scale, merge performance becomes a bottleneck. Discuss merge strategies in pandas for very large DataFrames (tens to hundreds of millions of rows): hash-based merge, sorting and merge-asof, chunked join, pre-aggregation, and offloading to databases or distributed frameworks. Provide recommendations and a sample chunked-merge code pattern.
EasyTechnical
55 practiced
You get a dataset in a long format: columns ['date','store','product','sales']. Write pandas code to (a) pivot to wide format with stores as rows and products as columns (sales as values), (b) melt it back to long format, and (c) perform a pivot_table with aggregation (sum) and margins. Explain index/columns/values and how to handle duplicates during pivot.
MediumTechnical
59 practiced
Translate the following SQL logic into pandas: "SELECT user_id, COUNT(*) AS purchases, SUM(amount) AS total FROM transactions WHERE status='complete' AND created_at >= '2024-01-01' GROUP BY user_id HAVING COUNT(*) > 5 ORDER BY total DESC LIMIT 100". Provide the pandas equivalent code and explain any important differences in execution model and performance implications.
MediumTechnical
55 practiced
Explain how pandas MultiIndex works. Given a DataFrame df with MultiIndex on ['country','city'] and columns ['year','population'], show how to (a) select all rows for a country, (b) swaplevels and sort_index, (c) reset_index to flatten. Provide code examples and discuss when a MultiIndex is useful vs when a single-index flattened DataFrame is preferable.
MediumTechnical
62 practiced
You have a DataFrame with nested JSON in a column 'payload' (strings of JSON). Using pandas show how to expand the JSON into separate columns (flat) and normalize lists inside the payload into separate rows if needed. Provide examples using json_normalize and .explode, and discuss performance considerations.

Unlock Full Question Bank

Get access to hundreds of Pandas Data Manipulation and Analysis interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.