Answers for "rearrage columns of a dataframe"

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
Posted by: Guest on October-23-2020
3

how to move columns in a dataframen in python

df = df[['column1', 'column2','column3']]
Posted by: Guest on April-11-2020

Code answers related to "rearrage columns of a dataframe"

Python Answers by Framework

Browse Popular Code Answers by Language