I have a Pandas dataframe where I am trying to replace the values in each group by the mean of the group. On my machine, the line df[\"signal\"].groupby(g).transform(n
df[\"signal\"].groupby(g).transform(n
Inspired by Jeff's answer. This is the fastest method on my machine:
pd.Series(np.repeat(grp.mean().values, grp.count().values))