Simplified example - I have a dataframe with an 'ID' column, a 'value' column and a 'category' column. Each ID is given a category between 0 and 4 and currently have no meaning other to differentiate the groups.
I want to give the group numbers meaning based on the 'value' column - e.g the group with the lowest values in the 'value' column become group 0, the group with the highest values in the 'value' column become group 4, instead of the random group numbers they have currently. Ideas on how to approach this? I've looked at ranks etc but this ranks all IDs in a group, and the groups can have 50+ IDs. I need to retain the current groupings, but give them more meaningful category numbers
Dataframe sample as is:
Expected result:
Background - the groups have actually been arrived at through kmeans clustering the value column. Kmeans though doesn't give any meaning to the category numbers as there would normally be several dimensions to the clustering not just one, and so doing this wouldn't make sense outside of on a single column. In the real world, I'm doing this on a big df with tons of value and category columns so I'd be doing the process on each. I know there may be better ways of categorising a 1D array other than kmeans, but i want to ignore that for now and deal with the problem as above (there will be other applications for solving it for me this way elsewhere).
Thanks

