code: 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)
docs: Computue the score percentile for the specified window.