title: Pandas: increase speed of rolling window (apply a custom function)
body: <p>I'm using this code to apply a function (<code>funcX</code>) on my data-frame using a rolling window. The main issue is that the size of this data-frame (<code>data</code>) is very large, and I'm searching for a faster way to do this task.</p>
  
  <pre><code>import numpy as np
  
  def funcX(x):
      x = np.sort(x)
      xd = np.delete(x, 25)
      med = np.median(xd)
      return (np.abs(x - med)).mean() + med
  
  med_out = data.var1.rolling(window = 51, center = True).apply(funcX, raw = True)
  </code></pre>
  
  <p>The only reason for using this function is that the calculated median is the median after removing the middle value. So it's different with adding <code>.median()</code> at the end of the rolling window.</p>