O'Reilly logo

Hands-On Data Analysis with NumPy and pandas by Curtis Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Index sorting

When talking about sorting, we need to think about what exactly we are sorting. There are rows, columns, their indices, and the data they contain. Let's first look at index sorting. We can use the sort_index method to rearrange the rows of a DataFrame so that the row indices are in order. We can also sort the columns by setting the access parameter of sort_index to 1. By default, sorting is done in ascending order; later rows have larger values than earlier rows, but we can change this behavior by setting the ascending value of the sort_index value to false. This sorts in descending order. By default, this is not done in place; you need to set the in place argument of sort_index to true for that.

While I have emphasized sorting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required