Skip to main contentSkip to solution

NameTestCourseMarks
Ajay1Commerce50
Alok1Information practices40
Arun1Physics60

Consider the above given dataframe as 'df'.

With reference to the pandas function sort_values(), which parameter is used to specify the column name?

Solution

✅ Correct Option: 2

The by parameter of sort_values() takes the column name (or a list of column names) to sort on, so df.sort_values(by=['Marks']) sorts the rows by the Marks column in ascending order.


Options 1, 3 and 4: using, with and in are not parameters of sort_values(), so they raise a TypeError. Note that with and in are also reserved Python keywords, so they cannot be used as argument names at all.

Use ascending=False along with by to sort in descending order.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question