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