Sorting a pandas DataFrame

In this section, we will learn about the pandas sort_values method. We will also use various methods to sort a pandas DataFrame and learn how to sort a pandas series object.

We will start by importing the pandas module and reading the dataset of house prices from into the Jupyter Notebook. First, let's start with the simple type of sorting. We will use pandas' sort_values method for this. For example, imagine that we want to sort the data by the Metro column. We need to pass Metro as a parameter to the sort_values method, and call the method on the DataFrame as follows:


This shows that the data has been sorted by the Metro column, as shown in the following screenshot:

If ...

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.