'Long processing time of groupby

I have about 5M records/rows in my dataframe and I need to perform a rolling aggregation using groupby on different time frames (3 months down to 1 day).

An example of the syntax I'm using is as bellow:

df.groupby(by='New_ID').resample("M")["is_approved"].sum().rolling(3).sum().rename("N_App_3M").fillna(0)

Unfortunately it takes inconveniently too much time.

Any inputs and ideas would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source