Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Sort by multiple columns in Pandas

sort_values can take multiple columns and each of the column can have different order for performing order by operation

Example : Sort students by class and within same class order by the names in reverse order
import pandas
data = pandas.DataFrame({'StudentName' : ['Anil', 'Musk','Bill'], 
                        'Class' : [1,2,2], 
                        'Age' : [6, 7, 8 ]})
data.sort_values(by=["Class","StudentName"], ascending=[True, False])


Output
indexAgeClassStudentName
061Anil
172Musk
282Bill