Save up to $499! Grab all Python courses for $49 or all online courses we’ve ever launched for only $169. Only Feb 11-16. Happy Valentine's!
13. Sorting values in groups


Good. You probably noticed that the mean values of grouped rows were not sorted. Luckily, we can change that. We’ll use the sort_values() function that you already know.


We will get the following result:

203 5837.000000
185 5060.000000
198 3658.666667
191 2366.500000
180 1689.000000
Name: aces, dtype: float64

Note that we can specify ascending/descending order inside sort_values(), but we don’t specify any column names. The expression grouped['aces'].mean() creates a Series, so there is only one column (aces).


Group all movies by director (movies_by_director), show the average rating for each director, and sort the results from best to worst ratings.

Stuck? Here's a hint!

Start by grouping the rows by directors:


Then, select the rating column, and use the mean() function, as in the instruction. Next, use the sort_values function.