title: Rolling window on multiple columns
body: <p>I am facing the following problem:
  I need to calculate the slope between two points based on height and distance. </p>
  
  <p>I use a rolling window of 50, with center = True. So for a certain row, the slope is calculated based on -25 indices and +25 indices. So for example, if the height at -25 (StartIndex) is 80 and the height at +25 (EndIndex) is 90 and each row represents 10 meters, then the slope would be: (90-80)/500 = 0.02</p>
  
  <p>However, the height at -25 and +25 could be a NaN value. In case of a NaN value at -25, StartIndex would become -24 (and if that is also a NaN, StartIndex would become -23, et cetera). The same goes for EndIndex.</p>
  
  <p>Now I created the following function and applied in on a rolling window. However, only the height is returned from the rolling window. </p>
  
  <p>Hence, I want to know how I can return two columns after a rolling window, in order to do some calculations with .apply(calculate_slope).</p>
  
  <p>I created this function and applied it.</p>
  
  <pre><code>def calculate_slope(df):
      df = df[df['Height'].notna()]
  
      StartIndex, EndIndex = df.iloc[0]['Height'], df.iloc[-1]['Height']
      first_KM, last_KM = df.iloc[0]['KM'], df.iloc[-1]['KM'] 
  
      slope = (EndIndex - StartIndex)/(last_KM - first_KM)  
  
      return slope
  </code></pre>
  
  <pre><code>def get_slope(df, window_size=50):
      return df.assign(
          slope = lambda d: (d[['Height','KM']]
                               .rolling(window=window_size, center=True, min_periods=1)
                               .apply(calculate_slope, raw=False)
                              )
      )
  </code></pre>
  
  <p>This is the example dataframe.</p>
  
  <pre><code>    KM        Height
  0   0.25      NaN
  1   0.5       2.0
  2   0.75      3.0
  3   1.0       NaN
  4   1.25      5.0
  5   1.5       6.0
  6   1.75      7.0
  7   2.0       8.0
  8   2.25      NaN
  </code></pre>
  
  <p>So if we set the window_size = 5, the expected result for df.iloc[4] should be: </p>
  
  <p>slope = (7 - 3)/(1.75 - 0.75) = 4.0
  Where 7 is <code>df.iloc[-1]['Height']</code>
  3 is <code>df.iloc[0]['Height']</code>
  1.75 is <code>df.iloc[-1]['KM']</code>
  and 0.75 <code>df.iloc[0]['Height']</code></p>
  
  <p>However, I get an immediate error, since the dataframe after rolling window does not know 'Height' </p>
  
  <pre><code>KeyError: 'Height'
  </code></pre>
  
  <p>So how do I get the 'Height' and 'KM' after the rolling when apply?</p>