FunctionRacerProblemsRace

Share of Sales

EasypandasPython

sales has columns region and amount (positive numbers); a region can appear in several rows. Return a dictionary mapping each region to its percentage of the total of all amounts, as a float (so the values add up to 100).

Example 1

sales {"region":["n","s","n"],"amount":[10,20,10]}
returns {"n":50.0,"s":50.0}

n sold 20 of 40, so 50.0; s also 50.0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems