What is the difference between sort_values and sort_index?

The difference is entirely in the way it is called. The source code for sort is literally a one-line call to sort_index.


As the question was updated to ask for the difference between sort_values (as sort is deprecated) and sort_index, the answer of @mathdan is no longer reflecting the current state with the latest pandas version (>= 0.17.0).

  • sort_values is meant to sort by the values of columns
  • sort_index is meant to sort by the index labels (or a specific level of the index, or the column labels when axis=1)

Previously, sort (deprecated starting from pandas 0.17.0) and sort_index where indeed almost identical (both methods could sort by both columns and index). But this confusing situation has been solved in 0.17.0.
For an overview of the changes in the sorting API, see http://pandas.pydata.org/pandas-docs/stable/whatsnew/v0.17.0.html#changes-to-sorting-api

Tags:

Python

Pandas