I have a dataframe that looks like this (link to csv):
time , value
0 , 10
1 , 20
2 , 35
3 , 30
4 , 40
5 , 40
6 , 60
And I want to fill another column recentActive based on the values from this smaller dataframe (link to csv):
time , value , activatedTime , deactivatedTime
1 , 20 , 1 , 5
3 , 30 , 3 , 4
In the recentActive column we should have the the most recent activated value that has not been deactivated yet. Once a value is deactivated, then we should fill it with the previous still active value. The final dataframe should look like this:
time , value , recentActive
0 , 10 , NaN
1 , 20 , 20 (t=1 activated)
2 , 30 , 20
3 , 30 , 30 (t=3 activated)
4 , 40 , 30 (t=3 deactivated)
5 , 40 , 20 (t=1 deactivated)
6 , 60 , NaN (no active values)
How can I do this? Preferably just using vectorized operations, thanks!