Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

how to move the last column to the first column in pandas

cols = [df.columns[-1]] + [col for col in df if col != df.columns[-1]]
df = df[cols]
Comment

PREVIOUS NEXT
Code Example
Python :: save pandas into csv 
Python :: Scrape the text of all paragraph in python 
Python :: python legend outside 
Python :: requests post with headers python 
Python :: intersection in list 
Python :: boston dataset sklearn 
Python :: flask return html 
Python :: mongodb check if substring in string 
Python :: get all files within multiple directories python 
Python :: python how to set multiple conditional for single var 
Python :: python armstrong number 
Python :: make csv lowercase python 
Python :: how to get the code of a website in python 
Python :: create np nan array 
Python :: except index out of range python 
Python :: json load python 
Python :: load static files in django 
Python :: plt.figure resize 
Python :: pyhton turtle kill 
Python :: How to Copy a File in Python? 
Python :: internet explorer selenium 
Python :: skip rows in pandas read excel 
Python :: get gpu name tensorflow and pytorch 
Python :: how to get iheight in pyqt5 
Python :: python faker 
Python :: get values using iloc 
Python :: random word py 
Python :: run sql query on pandas dataframe 
Python :: PIL Make Circle 
Python :: python: select specific columns in a data frame 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =