I have a dataframe(assuming large data set):
date | Security_Price | Benchmark_Price |
---|---|---|
2023-12-20 | 100.0 | 100.0 |
2023-12-21 | 105.0 | 95.0 |
2023-12-22 | 110.0 | 98.0 |
2023-12-23 | 110.0 | 100.0 |
2023-12-24 | 112.0 | 100.0 |
2023-12-25 | 112.0 | 100.0 |
2023-12-26 | 112.0 | 105.0 |
2023-12-27 | 115.0 | 107.0 |
2023-12-28 | 118.0 | 107.0 |
2023-12-29 | 120.0 | 107.0 |
2023-12-30 | 120.0 | 110.0 |
2023-12-31 | 107.0 | 108.0 |
I would like to achieve this : if on a certain date, security price == security_price.shift(1) or benchmark_price == benchmark_price.shift(1) then both security_price and benchmark_price should use the previous valid value. Like this:
date | Security_Price | Benchmark_Price |
---|---|---|
2023-12-20 | 100.0 | 100.0 |
2023-12-21 | 105.0 | 95.0 |
2023-12-22 | 110.0 | 98.0 |
2023-12-23 | 110.0 | 98.0 |
2023-12-24 | 112.0 | 100.0 |
2023-12-25 | 112.0 | 100.0 |
2023-12-26 | 112.0 | 100.0 |
2023-12-27 | 115.0 | 107.0 |
2023-12-28 | 115.0 | 107.0 |
2023-12-29 | 115.0 | 107.0 |
2023-12-30 | 120.0 | 110.0 |
2023-12-31 | 107.0 | 108.0 |