Examples
import numpy as np
import pandas as pd
s = pd.Series(['p', 'q', 'r', 's'], index=[3, 2, 4, 5])
s.sort_index()
Sort Descending
s.sort_index(ascending=False)
Sort Inplace
s.sort_index(inplace=True)
s
By default NaNs are put at the end, but use na_position to place them at the beginning
s = pd.Series(['p', 'q', 'r', 's'], index=[3, 2, 4, np.nan])
s.sort_index(na_position='first')
Specify index level to sort
arrays = [np.array(['xx', 'xx', 'ff', 'ff',
'bb', 'bb', 'br', 'br']),
np.array(['two', 'one', 'two', 'one',
'two', 'one', 'two', 'one'])]
s = pd.Series([2, 3, 4, 5, 6, 7, 8, 9], index=arrays)
s.sort_index(level=1)
Does not sort by remaining levels when sorting by levels
s.sort_index(level=1, sort_remaining=False)