pandas sort groups code example
Example 1: sort values within groups pandas dataframe
import pandas as pd
df = pd.DataFrame({'A':[1, 2, 3, 4, 5, 6],
'B':[0, 1, 2, 0, 1, 2]})
df.groupby('B').apply(lambda x: x.sort_values('A', ascending = True))
Example 2: Group based sort pandas
df_scored.sort_values('Score', ascending= False).sort_index(level='Index1', sort_remaining=False)