Sorting a DataFrame

Pandas provides functions to sort data in different ways. Let’s see how this can be done in this lesson.

Pandas provides two types of sorting, by index or by values. There is a third option, which combines both index and value.

Sort DataFrame by index

Most of the time, our index is meaningless and starts from zero. However, in some cases, the index has its own meaning, which can be used to sort the data.

The default sorting order is ascending. If you need a descending order, pass the ascending=False to the function.

Notice: The sorting is not in place. The result is returned by the function sort_index.

Get hands-on with 1400+ tech skills courses.