title: Python pandas rolling_apply two column input into function
body: <p>Following on from this question <a href="https://stackoverflow.com/questions/21025821/python-custom-function-using-rolling-apply-for-pandas">Python custom function using rolling_apply for pandas</a>, about using <code>rolling_apply</code>. Although I have progressed with my function, I am struggling to deal with a function that requires two or more columns as inputs:</p>
  
  <p>Creating the same setup as before</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import random
  
  tmp  = pd.DataFrame(np.random.randn(2000,2)/10000, 
                      index=pd.date_range('2001-01-01',periods=2000),
                      columns=['A','B'])
  </code></pre>
  
  <p>But changing the function slightly to take two columns.</p>
  
  <pre><code>def gm(df,p):
      df = pd.DataFrame(df)
      v =((((df['A']+df['B'])+1).cumprod())-1)*p
      return v.iloc[-1]
  </code></pre>
  
  <p>It produces the following error:</p>
  
  <pre><code>pd.rolling_apply(tmp,50,lambda x: gm(x,5))
  
    KeyError: u'no item named A'
  </code></pre>
  
  <p>I think it is because the input to the lambda function is an ndarray of length 50 and only of the first column, and doesn't take two columns as the input. Is there a way to get both columns as inputs and use it in a <code>rolling_apply</code> function.</p>
  
  <p>Again any help would be greatly appreciated...</p>