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
104 practiced

You're preparing a free-text product review column for a bag-of-words model and notice mixed casing, stray punctuation, inconsistent unicode (curly quotes, accented characters), and some genuinely missing reviews. Walk through how you'd normalize this column, and what you'd watch out for performance-wise if it has tens of millions of rows.

HardTechnical
54 practiced

A pivot_table produced hierarchical columns like ('sales','sum') and ('sales','mean'). Write robust pandas code to flatten MultiIndex columns into single strings like 'sales_sum' and ensure deterministic ordering. Also describe how to handle potential duplicate names after flattening and how to avoid clashing column names.

HardTechnical
67 practiced

You need to pivot a dataset with a high-cardinality 'metric' column (thousands of distinct metric names) into a wide table, but any single product-date only ever has values for a handful of those metrics. A naive pivot_table would create an enormous, mostly-empty matrix. Propose a memory-efficient way to produce this wide table and show code for it.

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
109 practiced

Write pandas code to remove groups with fewer than 3 transactions per customer in DataFrame df_orders where each group is defined by customer_id. Use groupby.filter and explain how groupby.filter differs from groupby.transform in terms of return shape and alignment.

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.