I have generic DataFrame with float numbers and no NaN's or Inf's. I want to compute the rolling Z-Score over the column Values
and took help of Scipy's z-score.
This works, but it's computing Z-Score over the whole column i.e. not rolling:
from scipy.stats import zscore
df['Z-Score'] = zscore(df['Values'])
This is what I want to do but it's giving me an error:
from scipy.stats import zscore
window_size = 5
df['Z-Score'] = df['Values'].rolling(window_size).apply(lambda s: zscore(s))
I get TypeError: cannot convert the series to <class 'float'>
.
I've searched over and over but can't find what the issue is. What am I doing wrong?
I know I can implement the zscore
function myself which is more performant but I'd rather use a library.