Applying weighted average function to column in pandas groupby object, carrying over the weights to calculate uncertainties
问题 I have tried to expand on this question to generalize to the case when one wants to carry over the sum of the weights, in a weighted average, so that one can append to the resulting dataframe the uncertainties on the weighted averages which are 1 / (sqrt(sum_of_weights)) Consider the sample dataframe import pandas as pd import numpy as np df5 = pd.DataFrame.from_dict({'Lab': ['Lab1','Lab1','Lab1','Lab2','Lab2','Lab2','Lab3','Lab3','Lab3'], 'test_type': ['a','a','b','b','c','c','a','a','a'],