1. Home
  2. Data Science
  3. Pandas
  4. Which pandas call returns a DataFrame sorted by the column…

Added 30 Nov -0001

Which pandas call returns a DataFrame sorted by the column 'marks' in descending order?

  1. df.order_by('marks', ascending=False)
  2. df.rank_values('marks', ascending=False)
  3. df.sort_values('marks', ascending=False) Correct answer
  4. df.sort_index('marks', ascending=False)

Correct answer

C. df.sort_values('marks', ascending=False)

14 views

MCQSEXAM

Explanation

sort_values orders the rows by the values of one or more columns, and ascending=False reverses the order; the sorted frame is returned as a new object unless inplace=True is passed. Several sort keys are supplied as a list, and na_position controls where missing entries are placed. sort_index is a different method that reorders by the row or column labels rather than by the data itself.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs