arrange columns pandas code example
Example 1: how to change the column order in pandas dataframe
df = df.reindex(columns=column_names)
Example 2: sort columns dataframe
df = df.reindex(sorted(df.columns), axis=1)
df = df.reindex(columns=column_names)
df = df.reindex(sorted(df.columns), axis=1)