I'm trying to improve the runtime speed of pandas rolling apply. My input dataframe is pretty big [df.shape=(257,2000000)] so I'm getting runtimes on the order of a number of days, which is unacceptable.
Here's my function:
def rolling_grad(y):
model = stats.linregress(np.arange(len(y)), y)
return model[0]
That applies over every column in the df:
grad = df.rolling(30).apply(rolling_grad)
Essentially I'm after the slope in rolling windows of size 30 for each column. I've tried using swifter and pandarallel with no luck.
Any help/advice very much appreciated. Thanks!