I have df with two cols: age and y_hat, the df is sorted by age.
Example:
age y_hat
1 0.2
1 11.5
2 11.5
3 11.5
3 8
3 8
3 0.2
I want to give each row a number based on the y_hat value change (like bins), y_hat values are not sorted and can repeat themselves.
Desired output:
age y_hat bin
1 0.2 1
1 11.5 2
2 11.5 2
3 11.5 2
3 8 3
3 8 3
3 0.2 4