I have an example dataframe as shown below
x y dx
0 1 6.0 1.1
1 2 6.0 1.5
2 2 6.5 1.2
3 3 7.2 4.3
4 4 7.5 4.5
5 4 8.0 4.7
6 5 1.1 7.0
I would like to merge the rows if the values in column dx are within a range of 1 of each other. There will be no overlapping ranges. I can either keep one of those rows and drop the rest or take an average of all the rows. So the expected output would look like
x y dx
1 1 6.0 1.1
2 3 7.2 4.3
3 5 1.1 7.0
or
x y dx
0 1.67 6.17 1.26
1 3.67 7.57 4.5
2 5 1.1 7.0