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.

EasyTechnical
52 practiced

Write pandas code to filter rows using boolean indexing: from a DataFrame orders with columns ['order_id', 'user_id', 'amount', 'status', 'created_at'], obtain orders where amount > 100, status in ['complete','shipped'], and created_at between '2024-01-01' and '2024-03-31'. Explain how & and | should be used and why parentheses are required. Also show how to chain .query() as an alternative.

HardTechnical
73 practiced

You are given a free-text column 'customer_notes' containing entries such as 'Order 12345: delayed due to weather; ETA 2024-05-10' and other inconsistent formats. Demonstrate using pandas vectorized string methods or regex to extract order numbers, reason, and ETA date into separate columns, handling missing or malformed entries gracefully. Discuss performance tips for regex-heavy operations on millions of rows.

MediumTechnical
70 practiced

Implement a reusable pandas routine that imputes missing values in a numeric column using the median of each group defined by another column (for example, filling a missing income value using the median income for that customer's region). If a group has too few observations, or was never seen at all, fall back to the overall median. Explain how you would structure this so the same logic can be fit once and reapplied consistently to new data.

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.

HardTechnical
59 practiced

Explain what Copy-on-Write changed about when a pandas operation returns a view versus a copy, and why it is no longer something you can opt into or out of. Discuss what this means for code that used to rely on chained assignment sometimes working, and general strategies to avoid unnecessary copies and large temporary DataFrames when working with large datasets.

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.