how to sort columns by value pandas code example
Example 1: dataframe, sort by columns
final_df = df.sort_values(by=['2'], ascending=False)
Example 2: sort columns dataframe
df = df.reindex(sorted(df.columns), axis=1)
final_df = df.sort_values(by=['2'], ascending=False)
df = df.reindex(sorted(df.columns), axis=1)