Search⌘ K

Sorting

Explore how to sort pandas DataFrames by single or multiple columns using the sort_values function. Understand sorting by ascending and descending order, handling tie-breakers, and apply these techniques to analyze MLB player statistics effectively.

Chapter Goals:

  • Learn how to sort a DataFrame by its features
  • Write code to sort an MLB player's statistics

A. Sorting by feature

When we deal with a dataset that has many features, it is often useful to sort the dataset. This makes it easier to view the data and spot trends in the values.

In pandas, the sort_values function allows us to sort a DataFrame by one or more of its columns. The first argument is ...