Premium problem125. Quantity-Weighted Average Price

Medium Locked

sales has columns region, price and quantity.

Return a Series indexed by region giving the quantity-weighted average price: the total revenue of the region divided by its total quantity, not the plain mean of its prices. Sort by region.

Input

  region  price  quantity
0      N   10.0         1
1      N   20.0         9
2      S    5.0         2
3      S    5.0         3

Output

region
N    19.0
S     5.0
dtype: float64

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)