I have a dataset with the following columns - ID, Old Stage, New Stage and Cycle Number. Each ID has multiple rows (2+), depicting a series of back and forth between old and new stage; this is detailed by the Cycle Number.
I am trying to group multiple rows by ID (that's ok), but within that grouping I want to sort by Cycle Number. For e.g. if ID 1 has 6 cycles, I want cycle #6 to be listed first, then 5, 4, 3, etc.
grouped2 = df.groupby(['ID', 'Old_Stage', 'New_Stage'], as_index=False)['Cycle_Number'].max().sort_values(['Cycle_Number'], ascending=False)
print(grouped2)
This is what I tried, however, it only sorts the Cycle Numbers in descending order overall, not within the ID grouping.
EDIT
Current dataframe:
|ID |Old Stage |New Stage |Cycle Number|
|100|In Progress |Under Review|1
|100|Not Started |In Progress |0
|100|Under Review|Completed |2
|100|Completed |In Progress |3
Desired dataframe:
|ID |Old Stage |New Stage |Cycle Number|
|100|Completed |In Progress |3
| |Under Review|Completed |2
| |In Progress |Under Review|1
| |Not Started |In Progress |0