def rolling_percentileofscore(series, window, min_periods=None):
    """Computue the score percentile for the specified window."""
    import scipy.stats as stats

    def _percentile(arr):
        score = arr[-1]
        vals = arr[:-1]
        return stats.percentileofscore(vals, score)

    notnull = series.dropna()
    min_periods = min_periods or window
    if notnull.empty:
        return pd.Series(np.nan, index=series.index)
    else:
        return pd.rolling_apply(notnull, window, _percentile, min_periods=min_periods).reindex(series.index)
def rolling_percentileofscore ( series , window , min_periods = None ) : import scipy . stats as stats def _percentile ( arr ) : score = arr [ - 1 ] vals = arr [ : - 1 ] return stats . percentileofscore ( vals , score ) notnull = series . dropna ( ) min_periods = min_periods or window if notnull . empty : return pd . Series ( np . nan , index = series . index ) else : return pd . rolling_apply ( notnull , window , _percentile , min_periods = min_periods ) . reindex ( series . index )
Computue the score percentile for the specified window.