If I have a dataframe like this,
index User Value location1 1 1.0 4.5 2 1 1.5 5.23 1 3.0 7.04 1 2.5 7.55 2 1.0 11.56 2 1.25 14.17 2 2.0 13.08 2 3.5 14.09 3 2.0 2.410 3 3.5 4.311 3 1.0 5.412 3 3.0 5.313 4 1.0 11.014 4 3.0 12.3
How would I select the max VALUE for each user with the nearest neighbor (above and lower) location of the max location, and if there's only one nearest location of the max, retrieve them as well?
The final results should be like this,
index User Value location 2 1 1.5 5.23 1 3.0 7.04 1 2.5 7.56 2 1.25 14.17 2 2.0 13.08 2 3.5 14.09 3 2.0 2.410 3 3.5 4.312 3 3.0 5.313 4 1.0 11.014 4 3.0 12.3