From the course: pandas Essential Training

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Sorting a DataFrame or Series

Sorting a DataFrame or Series

- [Instructor] If you've found yourself staring at a jumbled mess of data, wishing there was an easy way to bring order to the chaos, then the sort_values method is your friend. You can arrange your data alphabetically or numerically to start with. So this is our DataFrame with three random indexes or rows, and let's sort by the athlete name. And you can see that we're sorting by the surname, and so we've got Edgar and Arvo Ossian and so on. Now let's take a look at what the type is for this output. And you can see visually that this is a series. Now what you can also do is to sort by athlete name for the entire DataFrame. So you do oo.sort_values and then you specify which column you're looking to sort by. And here, you can see, again, that we've got the entire DataFrame here and we're sorting by the athlete names that we saw earlier. So that's Abbye, Edgar and Aaltonen, Arvo and so on. And you can see that this is in fact a DataFrame and you can confirm that visually because this…

Contents