I have the dataframe comprised of 'Linear' and 'Delta' and need to create the 'New' column.
In:
Linear Delta
30 -3
60 1.4
65 -0.3
62 4.4
21 -2.5
18 -0.1
34 -3.1
30 -1.5
45 0.5
55 -1.4
43 2.8
51 4.7
62 2.7
Out:
Linear Delta New
30 -3
60 1.4 60.0
65 -0.3 59.7
62 4.4 64.1
21 -2.5 61.6
18 -0.1 61.5
34 -3.1 58.4
30 -1.5 56.9
45 0.5 57.4
55 -1.4 55.0
43 2.8 57.8
51 4.7 51.0
62 2.7 53.7
The algorithmic formula is the following one:
New[i] = IF( AND(Linear[i-1]<50,Linear[i]>50) , Linear , New[i-1]+Delta[i] )
I tried a lot of different approaches such as cumsum() but never found the solution. I have spent many hours but in vain.