Examples
import numpy as np
import pandas as pd
df = pd.DataFrame({
'c1': ['P', 'P', 'Q', np.nan, 'S', 'R'],
'c2': [2, 4, 9, 8, 7, 5],
'c3': [0, 4, 9, 5, 2, 3],
})
df
Sort by c1:
df.sort_values(by=['c1'])
Sort by multiple columns:
df.sort_values(by=['c1', 'c2'])
Sort Descending:
df.sort_values(by='c1', ascending=False)
Putting NAs first:
df.sort_values(by='c1', ascending=False, na_position='first')