pandas change column sequence code example
Example 1: reorder columns pandas
cols = df.columns.tolist()
# Rearrange the list any way you want
cols = cols[-1:] + cols[:-1]
df = df[cols]
Example 2: pandas reorder columns by name
#old df columns
df.columns
Index(['A', 'B', 'C', 'D'],dtype='***')
#new column format that we want to rearange
new_col = ['D','C','B','A'] #list of column name in order that we want
df = df[new_col]
df.columns
Index(['D', 'C', 'B', 'A'],dtype='***')
#new column order