I have the following pandas df:
         date  Price_Prev2  Price_Prev1         Ctr   ER
0  2021-02-26       150.62       150.41  Price_Prev2  100.0
1  2021-03-01       150.81       150.60  Price_Prev2    NaN
2  2021-03-02       151.14       150.94  Price_Prev2    NaN
3  2021-03-03       151.12       150.93  Price_Prev2    NaN
4  2021-03-04       151.00       150.79  Price_Prev2    NaN
5  2021-03-05       151.50       151.33  Price_Prev2    NaN
6  2021-03-08       151.14       150.98  Price_Prev2    NaN
7  2021-03-09       151.05       150.88  Price_Prev2    NaN
8  2021-03-10       151.11       150.93  Price_Prev1    NaN
9  2021-03-11       151.27       151.05  Price_Prev1    NaN
10 2021-03-12          NaN       150.99  Price_Prev1    NaN
11 2021-03-15          NaN       151.07  Price_Prev1    NaN
For all rows except 0, I want ER to be calculated referencing the target column, whose name is stored in column 'Ctr'. The formula is: ER = ER(previous row) * Target_column (current row) / Target column (previous row)
So, for example:
- ER at row 7 = ER(6) * 151.05 / 151.14. 
- ER at row 8 = ER(7) * 150.93 / 150.88 
This is the expected output:
    date    Price_Prev2 Price_Prev1 Ctr1    ER_1
0   2021-02-26  150.62  150.41  Price_Prev2 100.00
1   2021-03-01  150.81  150.60  Price_Prev2 100.13
2   2021-03-02  151.14  150.94  Price_Prev2 100.35
3   2021-03-03  151.12  150.93  Price_Prev2 100.33
4   2021-03-04  151.00  150.79  Price_Prev2 100.25
5   2021-03-05  151.50  151.33  Price_Prev2 100.58
6   2021-03-08  151.14  150.98  Price_Prev2 100.35
7   2021-03-09  151.05  150.88  Price_Prev2 100.29
8   2021-03-10  151.11  150.93  Price_Prev1 100.32
9   2021-03-11  151.27  151.05  Price_Prev1 100.40
10  2021-03-12  NaN     150.99  Price_Prev1 100.36
11  2021-03-15  NaN     151.07  Price_Prev1 100.41
ANy idea of how to achieve it? Thanks.
 
    