I have a dataframe as mentioned below:
row_no,last_price,time
01,110.50,10:09
02,111.60,10:09
03,111.50,10:09
04,112.00,10:09
05,112.00,10:10
06,112.60,10:10
07,112.50,10:10
08,113.10,10:10
09,114.30,10:11
10,114.50,10:11
11,115.70,10:11
12,116.50,10:12
13,116.30,10:12
14,116.20,10:12
15,116.50,10:13
16,117.80,10:13
17,117.90,10:13
18,117.50,10:14
19,118.70,10:14
20,118.90,10:14
21,118.30,10:14
22,118.50,10:15
23,119.60,10:15
24,119.50,10:15
25,119.80,10:15
Row_No Column is added for understanding purpose.
Example for Last Row = 25: Values should be calculated as below:
- Need to Calculate "Price_Change_in_last_2mins" in new Column i.e. (row 25 last_price - row 15 last_price)*100/ (row 15 last_price)
- Need to Calculate "Price_Range_before_2mins" (period 2 min) in new Column i.e. (max value of last_price from row 05 to row 14) - (min value of last_price from row 05 to row 14)*100/ (min value of last_price from row 05 to row 14)
I want the result like:
row_no,last_price,time,Price_Change_in_last_2mins,Price_Range_before_2mins
01,110.50,10:09,NaN,NaN
02,111.60,10:09,NaN,NaN
03,111.50,10:09,NaN,NaN
04,112.00,10:09,NaN,NaN
05,112.00,10:10,NaN,NaN
06,112.60,10:10,NaN,NaN
07,112.50,10:10,NaN,NaN
08,113.10,10:10,NaN,NaN
09,114.30,10:11,NaN,NaN
10,114.50,10:11,NaN,NaN
11,115.70,10:11,NaN,NaN
12,116.50,10:12,NaN,NaN
13,116.30,10:12,NaN,NaN
14,116.20,10:12,NaN,NaN
15,116.50,10:13,NaN,NaN
16,117.80,10:13,NaN,NaN
17,117.90,10:13,,NaN,NaN
18,117.50,10:14,0.85,4.49
19,118.70,10:14,1.88,4.49
20,118.90,10:14,2.06,4.49
21,118.30,10:14,1.55,4.49
22,118.50,10:15,1.72,3.86
23,119.60,10:15,2.66,3.86
24,119.50,10:15,2.57,3.86
25,119.80,10:15,2.83,3.86