Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14155

Bidirectional replace value in pandas

$
0
0

I have a dataframe(assuming large data set):

dateSecurity_PriceBenchmark_Price
2023-12-20100.0100.0
2023-12-21105.095.0
2023-12-22110.098.0
2023-12-23110.0100.0
2023-12-24112.0100.0
2023-12-25112.0100.0
2023-12-26112.0105.0
2023-12-27115.0107.0
2023-12-28118.0107.0
2023-12-29120.0107.0
2023-12-30120.0110.0
2023-12-31107.0108.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:

dateSecurity_PriceBenchmark_Price
2023-12-20100.0100.0
2023-12-21105.095.0
2023-12-22110.098.0
2023-12-23110.098.0
2023-12-24112.0100.0
2023-12-25112.0100.0
2023-12-26112.0100.0
2023-12-27115.0107.0
2023-12-28115.0107.0
2023-12-29115.0107.0
2023-12-30120.0110.0
2023-12-31107.0108.0

Viewing all articles
Browse latest Browse all 14155

Trending Articles