Answers for "python move column position"

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 "python move column position"

Python Answers by Framework

Browse Popular Code Answers by Language