By columns
df.sort_values(by=['col1'])
df.sort_values(by=['col1', 'col2'])
df.sort_values(by='col1', ascending=False)
df.sort_values(by='col1', ascending=False, na_position='first')
By rows
0 col1 col2 col3
row1 222 16 23
row2 333 31 11
row3 444 34 11
df.sort_values(by='row2',axis=1)
output:
0 col1 col2 col3
row1 23 16 222
row2 11 31 333
row3 11 34 444
df.sort_values(by='row2',axis=1,ascending=False)
output:
0 col1 col2 col3
row1 222 16 23
row2 333 31 11
row3 444 34 11
By multiple rows
df.sort_values(by=['row1','row2'],axis=1,ascending=False)
Like this:
Like Loading...