I have dataframe with columns value,ID,distance and distance2. i want to extract previous row when value of column distance or distance2 change from 0 to value range for distance column 4000 to 5000 and for distance2 column when value change from 0 to range 3000 to 4000 .
here is my example df
df=pd.DataFrame({'value':[3,4,7,8,11,20,15,20,15,16],
'ID':[2,2,8,8,8,2,2,2,5,5],
'distance':[0,0,0,4008,0,0,4820,0,0,0],'distance2':[0,0,0,3006,0,0,0,1,3990,0]})
value ID distance distance2
0 3 2 0 0
1 4 2 0 0
2 7 8 0 0
3 8 8 4008 3006
4 11 8 0 0
5 20 2 0 0
6 15 2 4820 0
7 20 2 0 1
8 15 5 0 3990
9 16 5 0 0
desired output
value ID distance distance2
0 7 8 4008 3006
1 20 2 4820 0
2 20 2 0 3990