Which pandas call returns a DataFrame sorted by the column 'marks' in descending order?
Correct answer
C. df.sort_values('marks', ascending=False)
14 views
C. df.sort_values('marks', ascending=False)
14 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.