order columns dataframe python code example
Example 1: how to change the column order in pandas dataframe
df = df.reindex(columns=column_names)
Example 2: dataframe, sort by columns
final_df = df.sort_values(by=['2'], ascending=False)
df = df.reindex(columns=column_names)
final_df = df.sort_values(by=['2'], ascending=False)