Se7enSquared
10/23/2019 - 4:12 PM

Pandas re-order columns

Example:

A B C D x x x x

# To swap A & C above:
# Get a list of the column names
cols = list(df.columns.values)

df = df[cols[2] + cols[1] + cols[0] + cols[3])

# safer:
df = df['C', 'B', 'A', 'D']