sort dataframe by length of groups python code example Example: how to sort dataframe in python by length of groups df.groupby('col1').size().sort_values(ascending=False)