Sorting by values
If we wish to sort the rows of a DataFrame or the elements of a series, we need to use the sort_values method. For a series, you'd call sort_values and call it a day. For a DataFrame though, you would need to set the by parameter; you can set by to a string, indicating the column you want to sort by, or to a list of strings, indicating column names. Sorting will first proceed according to the first column in this list; then, when ties appear, sorting will be according to the next column, and so on.
So, let's demonstrate some of these sorting techniques. We sort the values of the DataFrame according to the column AAA, shown in the following screenshot:
Notice that all the entries in AAA are now in order, though not much ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access