title: Rolling difference in Pandas
body: <p>Does anyone know an efficient function/method such as <code>pandas.rolling_mean</code>, that would calculate the rolling difference of an array</p>
  
  <p>This is my closest solution:</p>
  
  <pre><code>roll_diff = pd.Series(values).diff(periods=1)
  </code></pre>
  
  <p>However, it only calculates single-step rolling difference. Ideally the step size would be editable (i.e. difference between current time step and n last steps).</p>
  
  <p>I've also written this, but for larger arrays, it is quite slow:</p>
  
  <pre><code>def roll_diff(values,step):
      diff = []
      for i in np.arange(step, len(values)-1):
          pers_window = np.arange(i-1,i-step-1,-1)
          diff.append(np.abs(values[i] - np.mean(values[pers_window])))
      diff = np.pad(diff, (0, step+1), 'constant')
      return diff
  </code></pre>