From the course: pandas Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using sort_index()

Using sort_index() - pandas Tutorial

From the course: pandas Essential Training

Start my 1-month free trial

Using sort_index()

- [Instructor] Now I want to sort index. Sort index allows for all the items to be sorted by that index. The advantage of this is that when you have a particularly large data set, sorting the index reduces the time to access any subset of that data. You can sort objects by a label along the axis. Let's head over to the Jupyter Notebook to look at a couple of examples. Let's reuse the ATH data frame that we created in the previous video. So ath.head gives us the first couple of rows. Now let's set the index to the athlete name, so ath.set index to athlete. And we'll do that in place. So if we're now doing ath.head, and now we can see that the index is by the athlete's name. So let's now sort that index. So ath.sort index, and we specify that that's looking at in place equals true. So we want to change that in place equals false to in place equals true. And let's see what changes we see to the ATH data frame. And we can see that the athlete is now the index for the data frame. And this…

Contents