python get index of sorted df code example Example 1: pandas sort dataframe by index df.sort_index() Example 2: how to sort index pd.sort_index()