Faster Way to Generate Rolling Calculations on a list of columns within a groupby object
Clash Royale CLAN TAG #URR8PPP Faster Way to Generate Rolling Calculations on a list of columns within a groupby object I created this function to calculate the rolling stats for a list of feats in my df. This function works as intended but takes roughly 20min to run on my df which has about 1 million rows. Is there a faster way to do this in python/pandas ? def add_rolling_vars(df, feats, amounts, group): #creates rolling stats for a list of feats(columns) over a list of amounts[12,48](window sizes) #grouped by a group like $gvkey or $sector orig_feats = feats.copy() new_feats= for amount in amounts: for name in feats: df[group+'_'+name+f'_{amount}_sma'] = df.groupby(group)[name].rolling(amount,1).mean().values df[group+'_'+name+f'_{amount}_std'] = df.groupby(group)[name].rolling(amount,1).std().values df[group+'_'+name+f'_{amount}_min'] = df.groupby(group)[name].rolling(amount,1).min().values df[group...