def weighted_average_func(datacol, weightscol):
    """
    From https://stackoverflow.com/a/33881167
    A function that returns a function for computing a weighted 
    groupby mean    
    """
    def wavg(group):
        dd = group[datacol]
        ww = group[weightscol] * 1.0
        return (dd * ww).sum() / ww.sum()
    return wavg