Share of Group Total with transform

easy
Unit 5 · Pandas & Outliers0/3 to milestone

Given a DataFrame df with columns region, product and sales, implement add_shares(df) that returns a copy with two new columns:

  • share: each row's sales as a fraction of its region's total (use groupby(...).transform('sum'))
  • rank: rank within the region by sales, highest = 1, ties sharing the lower rank (method='min'), as integers

Keep the original row order.

#pandas#groupby2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Share of Group Total with transform · TechGradify