sort dataframe and keep first pandas code example Example: sort columns dataframe df = df.reindex(sorted(df.columns), axis=1)