Rolling qcut · Issue #10759 · pandas-dev/pandas (original) (raw)
I believe qcut would be much more useful if there was a convenient way to apply it to a rolling window instead of the whole Series object. Of course it's possible with rolling_apply, but that does window_size times more calculations that are necessary for the output. For something as trivial as checking how the current value compares to the ones around it, I'm forced to use this monstrosity:
pd.rolling_apply(arg,window,lambda x: pd.qcut(x,q,labels=False)[window/2],center=True)
instead of much more elegant pd.rolling_qcut(arg,window,q,center=True)