← All Python interview questions
Compute profit margin per category with groupby
MediumPandas — GroupByDeloitteAccenture
Finance wants a margin per category: total profit divided by total revenue, not the average of the row-level margins.
Write margins(df) that returns a Series indexed by category with the margin as a percentage rounded to 2 decimals, sorted from highest to lowest margin.
More Pandas — GroupBy questions
Practising alone only goes so far — our live cohorts pair Python and Pandas depth with dashboards, agentic analytics projects and mock interviews.
Explore the program