title: Applying lambda function to a pandas rolling window series
body: <p>I have a function which takes an array and a value, and returns a value. I would like to apply it to my Series <code>s</code> on a rolling basis, so the array is always the rolling window. Here's a minimal example of what I've tried (unsuccessfully), using <code>np.random.choice</code> in place of my real function. I find lots of examples for finding rolling means and other built-in functions, but can't get it to work for my arbitrary lambda function.</p>
  
  <pre><code>s = pd.Series([1,2,3,4,5,6,7,8,9])
  rolling_window = s.rolling(3)
  </code></pre>
  
  <p>First attempt:</p>
  
  <pre><code>new_values = s.apply(lambda x: np.random.choice(rolling_window, size=1)) 
  </code></pre>
  
  <blockquote>
    <p>ValueError: a [a is the first positional param of choice(), so refers to 'rolling_window'] must be 1-dimensional or an integer</p>
  </blockquote>
  
  <p>Another attempt:</p>
  
  <pre><code>new_values = rolling_window.apply(lambda x: np.random.choice(size=1))
  </code></pre>
  
  <blockquote>
    <p>TypeError: choice() takes at least 1 positional argument (0 given)</p>
  </blockquote>
  
  <p>...How do I apply an arbitrary lambda function (taking an array and a value) on each value in my Series, on each rolling-array window in my Series?</p>