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

Compare how SQL join operations and pandas.merge behave differently regarding duplicate key multiplicity and how pandas' validate parameter can help catch unexpected multiplicities. Provide examples of validate options like 'one_to_one' and 'one_to_many' and how they map to SQL assumptions.

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.

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.

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
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.

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.