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.

HardTechnical
56 practiced

Discuss when NumPy vectorized aggregation can meaningfully outperform pandas groupby for aggregating millions of rows by category label, and show a concrete example of that speedup. Then explain when pandas' own groupby implementation is preferable despite the difference.

EasyTechnical
66 practiced

Using pandas in Python, given a DataFrame 'events' with columns ['user_id','event_type','value','event_time'], provide code to compute: (1) total and average 'value' per 'event_type', (2) number of unique users per event_type, and (3) the top 5 event_types by total 'value'. Write readable pandas groupby expressions and explain the role of as_index and reset_index for returning DataFrames.

MediumTechnical
69 practiced

You filter a DataFrame into a subset and set values on one of its columns. Walk through what pandas is actually doing under the hood when it cannot tell whether that subset is an independent copy or a view into the original, why this used to be a silent correctness trap rather than just a noisy warning, and how you would rewrite the code to be unambiguously safe regardless of pandas version.

EasyTechnical
73 practiced

Explain the difference between DataFrame.loc and DataFrame.iloc in pandas. Provide Python examples showing selection by label vs integer position, slicing semantics (inclusive/exclusive), behavior with boolean arrays and callable indexing, and discuss pitfalls when the index contains integer labels or duplicate labels.

HardTechnical
62 practiced

You have a DataFrame with nested JSON in a column 'payload' (strings of JSON), where some fields inside the payload are themselves lists. Show how to expand this column into separate flat columns, and how to turn the list-valued fields into one row per list item where needed. Discuss the performance implications of doing this at scale.

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.