I have this dataframe. I need to replace NaNs in column rank to a value based on multiple conditions. If column min is higher than 3 previous rows of max column then rank equals to min. Otherwise, I need to copy the previous value of rank
max min rank
0 128.20 117.87 117.87
1 132.72 122.29 122.29
2 138.07 124.89 124.89
3 137.02 128.46 NaN
4 130.91 129.86 NaN
5 200.15 190.54 NaN
6 199.18 191.79 NaN
7 210.44 201.94 NaN
The desired result is
max min rank
0 128.20 117.87 117.87
1 132.72 122.29 122.29
2 138.07 124.89 124.89
3 137.02 128.46 124.89
4 130.91 129.86 124.89
5 200.15 190.54 190.54
6 199.18 191.79 190.54
7 210.44 201.94 201.94