I have a dataframe df like this :
ID NAME AGE
-----------------
M43 ab 32
M32 df 12
M54 gh 34
M43 ab 98
M43 ab 36
M43 cd 32
M32 cd 39
M43 ab 67
I need to sort the rows based on the ID column.
The output df_grouped should look like :
ID NAME AGE
-----------------
M43 ab 32
M43 ab 98
M43 ab 36
M43 cd 32
M43 ab 67
M32 df 12
M32 cd 39
M54 gh 34
I tried something like :
df_grouped = df.group_by(df.ID)
for id in list(df.ID.unique()):
grouped_df_list.append(df_grouped.get_group(id))
Is there any better way to do this ?
df.sort_values('ID')what you're after?IDcolumn has - say 6 unique entries, I need to group rows in these six chunks.sort_valuesonID. Try it.