Chapter 10: Hello sorting¶
Another simple but common technique for analyzing data is sorting.
What were the ten biggest contributions? We can find the answer by using the sort_values method to rearrange our list using the amount field.
Note that returns the DataFrame resorted in ascending order from lowest to highest. That is pandas default way of sorting.
To answer our question you’ll need to reverse that, so that values are sorted in descending order from biggest to smallest. It’s a little tricky at first, but here’s how to do it with sort_values.
You can limit the result to the top five by chaining the head method at the end.
We can now use the new variable to rank the five biggest supporting contributions by using sort_values again.
And now how about the opposition.