Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Sorting Data | Explore Dataset
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to Python for Data Analysis
SectionΒ 3. ChapterΒ 4
single

single

bookSorting Data

Swipe to show menu

We need sorting for ease of work.

We can sort our data in 2 ways: ascending sorting and descending sorting.

To perform the ascending sorting, use the following code:

DataFrame.sort_values(by = 'column_name', inplace = True)

If we want to perform descending, we have to turn off the ascending parameter.

DataFrame.sort_values(by = 'column_name', inplace = True, ascending = False)

If the parameter inplace is set to True (inplace = True), it will perform the operation inplace. Modify the original DataFrame itself. The return type is None.

Task

Swipe to start coding

Now we are going to practice sorting. We will sort 2 different DataFrame columns using ascending and descending sorting.

  1. Import the pandas using the pd alias.
  2. Perform an ascending sorting by the 'price' column.
  3. Perform a descending sorting by the 'user_id' column.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt