move columns pandas code example

Example 1: 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

Example 2: how to move columns in a dataframen in python

df = df[['column1', 'column2','column3']]

Example 3: pandas move columns around

df = df[['a', 'y', 'b', 'x']]