Applying multiple rolling functions to multiple columns of a pandas groupby rolling object?

Viewed 700

I am looking to do the following:

  1. Group a dataframe

  2. For each group, generate time windows (given a time unit)

  3. Within the resulting structure, take every column and apply multiple rolling summary statistic functions so that the result has a summary statistic for each group/time window combination.

Here is an example dataset:

gps_time,name,val_x,val_y
2017-07-04 11:20:23.423,bob,0.963,0.201
2017-07-04 11:20:24.492,bob,0.964,0.203
2017-07-04 11:20:24.499,bob,0.962,0.210
2017-07-04 11:20:25.627,sarah,0.893,0.010
2017-07-04 11:20:28.627,sarah,0.894,0.012
2017-07-04 11:20:29.613,sarah,0.895,0.014
2017-07-04 11:20:29.630,larry,-0.423,0.231
2017-07-04 11:20:30.423,larry,-0.431,0.22
2017-07-04 11:20:30.428,larry,-0.432,0.222

And the desired output for the above data, grouped by name and with a window of 1 second:

name,gps_time,val_x_mean,val_x_med,val_y_mean,val_y_med
bob,2017-07-04 11:20:23.423,0.963,0.963,0.201,0.201
bob,2017-07-04 11:20:24.492,0.963,0.963,0.2065,0.2065
sarah,2017-07-04 11:20:25.627,0.893,0.89,0.010,0.010
sarah,2017-07-04 11:20:28.627,0.8945,0.8945,0.013,0.013
larry,2017-07-04 11:20:30.423,-0.4287,-0.431,0.336,0.222

I've tried using a list comprehension to generate a bunch of data frames, but the process is really slow and I have to call it for every column.

1 Answers
Related