I have this df with 9 columns
x y1_x y2_x y3_x y4_x
0 -17.7 -0.785430 NaN NaN NaN
1 -15.0 NaN NaN NaN -3820.085000
2 -12.5 NaN NaN 2.138833 NaN
3 -12.4 NaN NaN 1.721205 NaN
4 -12.1 NaN 2.227343 2.227343 NaN
d1 d2 d3 d4
0 0.053884 NaN NaN NaN
1 NaN NaN NaN 0.085000
2 NaN NaN 0.143237 NaN
3 NaN NaN 0.251180 NaN
4 NaN 0.127343 0.440931 NaN
Between y1_x and y4_x I can only have 1 non NaN value per row.
The condition to choose which value is removed is explained in this example:
In row 4 there are 2 values between y1_x and y4_x
The value that becomes NaN is the one from y3_x because in that same row, d3 > d2