I have the following C data frame.
>>> C abc 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
I would like to add a new column d , where I apply the rolling function, in a fixed window (here 6), where I somehow fix the value C for each row (or date), One loop in this rolling function should be (pseudo) :
abcd 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
After this โloopโ I want to take all these 6 calculated lines in d and start a function call, which in turn will return one value, which should be stored in another column, e say:
abcde 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
Then this procedure will be repeated in the next window (again 6 long), for example:
abcde 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 abcde 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
Hope it's clear enough
Thanks N