I do not understand how the expected answer is sorted. The instructions say: Order the table by unique values in a descending order (not alphabetically). It does seem to be sorted in any manner.
Hi Rich. They’re ordering by the labels based on their meaning, going from much more than average down to very few points. It’s very similar to the example given in the lesson, but expanded to be more granular:
We want to sort the labels in an ascending or descending order, but using Series.sort_index() doesn’t work because the method can’t infer quantities from words like “few points”. Series.sort_index() can only order the index alphabetically in an ascending or descending order.
I think what I did for that lesson is I first use .value_counts() to find out the original order, and then base the index for the iloc on that.
So for example, if we look at the example from the lesson, this is what we get from wnba['PTS_ordinal_scale'].value_counts():
a lot of points 79
few points 27
many points 25
very few points 12
Since the result from .value_counts() is a Series, we can say that a lot of points is at index 0, few points is at index 1, etc. Based on this, if I wanted to use iloc to reorder the list from greatest to least based on the label meaning, I could use the order 0, 2, 1, 3 to reference each one. I can change the code to this: