I have huge dataframe and I need to calculate slope using rolling windows in pandas. The code below works fine but looks like numba is not able to parallelize it. Any other way to parallelize it or make it more efficient?
def slope(x):
length = len(x)
if length < 2:
return np.nan
slope = (x[-1] - x[0])/(length -1)
return slope
df = pd.DataFrame({"id":[1,1,1,1,1,2,2,2,2,2,2], 'a': [1,3,2,4,5,6,3,5,8,12,30], 'b':range(10,21)})
df.groupby('id', as_index=False).rolling(min_periods=2, window=5).apply(slope, raw = True, engine="numba", engine_kwargs={"parallel": True})
I get the following warning message :
The keyword argument 'parallel=True' was specified but no transformation for parallel execution was possible.
To find out why, try turning .....