📅  最后修改于: 2022-03-11 15:00:12.428000             🧑  作者: Mango
In [11]: g.apply(lambda x: pd.Series(np.average(x[["var1", "var2"]], weights=x["weights"], axis=0), ["var1", "var2"]))
Out[11]:
var1 var2
category
a 38.250000 34.000000
b 23.285714 6.428571