Question:

Which function is used to sort a Pandas DataFrame in descending order based on a column?

Show Hint

The parameter "ascending=False" is standard across SQL and Pandas.
Make sure to use the exact function "sort_values" instead of "sort".
Updated On: Jun 11, 2026
  • df.sort_values(by='column_name', ascending=False)
  • df.sort(by='column_name', order='desc')
  • df.order_by('column_name', reverse=True)
  • df.sort_data('column_name', descending=True)
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation




Step 1: Understanding the Question:

The question asks for the correct Pandas method and arguments to sort the rows of a DataFrame in descending order based on values in a specified column.



Step 2: Key Formula or Approach:

In Pandas, the function sort_values() is the built-in method to sort a DataFrame.
The key parameters are:
- by: Specifies the column name(s) to sort by.
- ascending: A boolean parameter. Setting it to False sorts the data in descending order. By default, it is True.



Step 3: Detailed Explanation:

Let's evaluate the options:
- Option (A) uses the correct method sort_values() with the parameters by='column_name' and ascending=False. This is the standard, modern Pandas syntax.
- Option (B) uses df.sort(), which is deprecated in modern Pandas versions, and the parameters order='desc' are incorrect.
- Option (C) uses df.order_by(), which is not a valid Pandas DataFrame function (it is SQL or Django ORM syntax).
- Option (D) uses df.sort_data(), which does not exist in Pandas.
Thus, option (A) is the only correct syntax.



Step 4: Final Answer:

The correct option is (A).
Was this answer helpful?
0
0