Calculate weighted average using a pandas/dataframe
I think I would do this with two groupbys. First to calculate the “weighted average”: If you set this as a column, you can groupby over it: Now the sum of this column is the desired: or potentially: