title: python pandas rolling function with two arguments
body: <p>My beginner's love for python is undergoing a hard trial...</p>
  
  <p>I need to calculate a function in a rolling window of a fixed length (let's say: 5). The function requires two parameters. I am well aware of the answer <a href="https://stackoverflow.com/questions/25675301/using-rolling-apply-with-a-function-that-requires-2-arguments-in-pandas">here</a> which is nearly identical, but I keep getting errors.</p>
  
  <p>My code is simple:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  import scipy as sp
  import scipy.stats
  
  df = pd.DataFrame( {'A' : np.arange(20), 'B' : np.random.randint(0,20,20)})
  
  def my_tau2(idx):
      x = df.loc[idx, 'A'].astype('float')
      y = df.loc[idx, 'B'].astype('float')
      return scipy.stats.mstats.kendalltau(x, y)[0] ## breaks without this [0]
  
  pd.rolling_apply(np.arange(len(df), dtype = np.dtype('int16')), 5, my_tau2)
  </code></pre>
  
  <p>And I keep getting the following error:</p>
  
  <pre><code>enter code
  File "&lt;ipython-input-6-d6cbc608d2f0&gt;", line 7, in &lt;module&gt;
  pd.rolling_apply(np.arange(len(df), dtype = np.dtype('int16')), 5, my_tau2)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\stats\moments.py", line 584, in rolling_apply
  kwargs=kwargs)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\stats\moments.py", line 240, in ensure_compat
  result = getattr(r, name)(*args, **kwds)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\window.py", line 863, in apply
  return super(Rolling, self).apply(func, args=args, kwargs=kwargs)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\window.py", line 621, in apply
  center=False)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\window.py", line 560, in _apply
  result = calc(values)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\window.py", line 555, in calc
  return func(x, window, min_periods=self.min_periods)
  File "D:\Users\502031217\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\window.py", line 618, in f
  kwargs)
  File "pandas\algos.pyx", line 1831, in pandas.algos.roll_generic (pandas\algos.c:51581)
  TypeError: a float is required
  </code></pre>
  
  <p>I've been struggling with that and I'm going bonkers.
  My module versions are:</p>
  
  <ul>
  <li>numpy: 1.11.0</li>
  <li>scipy: 0.17.1</li>
  <li>pandas: 0.18.1</li>
  <li>python: 3.5.1</li>
  </ul>
  
  <p>Any hints w.r.t. how to fix or calculate this in another way are wholeheartedly welcome.</p>