Data frame sorting on multiple columns

import pandas as pd

df = pd.read_csv(“D://data/employee.csv”)
df.sort_values(by=[‘department’, ‘salary’], ascending=[1, 0])

Output

empid name department salary
6 7 Jean admin 13000
0 1 John admin 10000
4 5 Mike finance 23000
5 6 Bill finance 15000
3 4 Martin finance 13000
7 8 Tim sales 17000
1 2 Peter sales 12000
2 3 James sales 10000

Published by Python programming examples for beginners

Abhay Gadkari is an IT professional having around experience of 20+ years in IT industry. He worked on web technologies and databases with Insurance and ERP projects.