I've already seen this question, but the desired outcome there is slightly different from mine.
Imagine a dataframe grouped thusly:
df.groupby(['product_name', 'usage_type']).total_cost.sum()
product_name usage_type
Lorem A 30.694665
B 0.000634
C 1.659360
D 0.000031
E 3339.140042
F 0.074340
Ipsum G 9.627360
A 19.053377
D 14.492155
Dolor B 9.698245
H 6993.792163
C 31947.955679
D 2150.400001
E 26.337789
Name: total_cost, dtype: float6
The output I want is the same structure, but with two properties:
- Order the product names by the sum of the costs
- Order the usage types lexicographically (happy alternative: ordering these by descending cost)
Such that the highest-cost products show up first, but still preserving the breakdown.
If it is significantly simpler, I'm okay with dropping the secondary sorting by usage type.