Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to move a column to last in pandas

print(df)
   col1  col2  col3
0     1    11   111
1     2    22   222
2     3    33   333

s = df.pop('col1')
new_df = pd.concat([df, s], 1)
print(new_df)
Output:

   col2  col3  col1
0    11   111     1
1    22   222     2
2    33   333     3
 
PREVIOUS NEXT
Tagged: #move #column #pandas
ADD COMMENT
Topic
Name
6+8 =