InterviewStack.io LogoInterviewStack.io

Python and Pandas for Data Analysis Questions

Programmatic data manipulation and analysis in Python and R. Covers pandas transformations, joins and reshaping, aggregation, working with PySpark for larger data, and using R for statistical analysis. Emphasizes clean, reproducible analytical code.

MediumTechnical
56 practiced

Write Python (pandas) code to compute weekly active users (WAU) from an event log events(user_id, event_time timestamp). Your code should: 1) compute WAU per ISO week, 2) compute week-over-week percentage change, and 3) handle missing days and timezone-aware timestamps. Explain any assumptions.

MediumTechnical
52 practiced

Given a sample DataFrame df with columns ['id', 'name', 'age', 'signup_date', 'score'] demonstrate with code and explanations the differences between df.loc, df.iloc and chained indexing. Show examples selecting rows 10-20, selecting by boolean condition (age > 30), selecting columns by label and by integer positions. Explain why chained indexing can be dangerous and how to avoid it.

MediumTechnical
55 practiced

Explain how a pandas MultiIndex works. Given a DataFrame df with a MultiIndex on ['country','city'] and columns ['year','population'], show how you would select every row for a single country, reorder and sort the index levels, and turn the MultiIndex back into plain columns. Discuss when a MultiIndex actually helps versus when a flat single index is easier to work with.

HardTechnical
64 practiced

Examine the code:

subset = df[df['A'] > 0]
subset['B'] = subset['C'] * 2

Using the pandas version you have installed, explain exactly what happens when this runs: does it silently do nothing, raise an error, or modify df, and why. Show the correct way to either modify df in place or work on a genuinely independent copy, and how you would tell which one you have before writing to it.

MediumTechnical
68 practiced

When should you prefer pivot_table over groupby + unstack? Given df with duplicates for some (store,date,product) combinations, write pandas code to create a matrix of summed sales with pivot_table using aggfunc='sum' and fill_value=0. Explain how pivot_table handles duplicates and compare performance.

Unlock Full Question Bank

Get access to all Python and Pandas for Data Analysis interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.