Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

change column order pandas

# Want to change column3 to show up first
df = pd.Dataframe({
  "column1":(1,2,3),
  "column2":(4,5,6),
  "column3":(7,8,9)
}
# From all solutions I could find, this seems to be the best performance wise:
col = df.pop(col_name)
df.insert(0, col.name, col)# <- works in place and returns None (at least for me)
  
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #change #column #order #pandas
ADD COMMENT
Topic
Name
5+3 =