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