Let\'s say that I have some data generated as follows:
N = 20 m = 3 data = np.random.normal(size=(N,m)) + np.random.normal(size=(N,m))**3
and t
Although this is not the prettiest solution, you could do something like this:
indx = df['indx'].copy() for indices in df.groupby('indx').groups.values(): df.loc[indices] -= df.loc[indices].mean() df['indx'] = indx