On January 21th at 14:15 UTC , progression through exercises will be unavailable for 10 minutes due to a planned maintenance break.
Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
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.