title: Rolling a function on a data frame
body: <p>I have the following data frame <code>C</code>.</p>
  
  <pre><code>&gt;&gt;&gt; C
                a    b   c
  2011-01-01    0    0 NaN
  2011-01-02   41   12 NaN
  2011-01-03   82   24 NaN
  2011-01-04  123   36 NaN
  2011-01-05  164   48 NaN
  2011-01-06  205   60   2
  2011-01-07  246   72   4
  2011-01-08  287   84   6
  2011-01-09  328   96   8
  2011-01-10  369  108  10
  </code></pre>
  
  <p>I would like to add a new column, <code>d</code>, where I apply a rolling function, on a fixed window (6 here), where I somehow, for each row (or date), <em>fix</em> the value <code>c</code>. One loop in this rolling function should be (pseudo):</p>
  
  <pre><code>              a    b   c   d
  2011-01-01    0    0 NaN   a + b*2 (a,b from this row, '2' is from 'c' on 2011-01-06)
  2011-01-02   41   12 NaN   a + b*2 (a,b from this row, '2' is still from 2011-01-06)
  2011-01-03   82   24 NaN   a + b*2
  2011-01-04  123   36 NaN   a + b*2
  2011-01-05  164   48 NaN   a + b*2
  2011-01-06  205   60   2   a + b*2
  2011-01-07  246   72   4   
  2011-01-08  287   84   6   
  2011-01-09  328   96   8   
  2011-01-10  369  108  10
  </code></pre>
  
  <p>After this "loop" I want to take all of these 6 calculated rows in <code>d</code> and run a function call, which in turn will return <em>one</em> value, that should be stored in another column, <code>e</code> say:</p>
  
  <pre><code>              a    b   c   d                               e
  
  2011-01-01    0    0 NaN   a + b*2 ---|                   NaN
  2011-01-02   41   12 NaN   a + b*2    |                   NaN
  2011-01-03   82   24 NaN   a + b*2    | These values      NaN
  2011-01-04  123   36 NaN   a + b*2    | are input to      NaN
  2011-01-05  164   48 NaN   a + b*2    | function          NaN
  2011-01-06  205   60   2   a + b*2 ---| yielding          X
  2011-01-07  246   72   4                value X in
  2011-01-08  287   84   6                column 'e'
  2011-01-09  328   96   8   
  2011-01-10  369  108  10
  </code></pre>
  
  <p>This procedure would then be iterated onto the <em>next</em> window (again 6 long) like:</p>
  
  <pre><code>              a    b   c   d             e
  2011-01-01    0    0 NaN   
  2011-01-02   41   12 NaN   a + b*4 (a,b from this row, '4' is from 'c' now from 2011-01-07)
  2011-01-03   82   24 NaN   a + b*4 (a,b from this row, '4' is still from 2011-01-07)
  2011-01-04  123   36 NaN   a + b*4
  2011-01-05  164   48 NaN   a + b*4
  2011-01-06  205   60   2   a + b*4       X
  2011-01-07  246   72   4   a + b*4
  2011-01-08  287   84   6   
  2011-01-09  328   96   8   
  2011-01-10  369  108  10
  
                a    b   c   d                               e
  
  2011-01-01    0    0 NaN                                  NaN
  2011-01-02   41   12 NaN   a + b*4 ---|                   NaN
  2011-01-03   82   24 NaN   a + b*4    | These values      NaN
  2011-01-04  123   36 NaN   a + b*4    | are input to      NaN
  2011-01-05  164   48 NaN   a + b*4    | function          NaN
  2011-01-06  205   60   2   a + b*4    | yielding          X
  2011-01-07  246   72   4   a + b*4 ---| value Y in        Y
  2011-01-08  287   84   6                column 'e'
  2011-01-09  328   96   8   
  2011-01-10  369  108  10
  </code></pre>
  
  <p>Hopefully this is clear enough,</p>
  
  <p>Thanks,
  N</p>