简体   繁体   中英

Move partial data from one column to another in Ms excel using Python

I have over 20,000 rows of data on excel and want to partial separate the data from column A to say column F. How can I do this using python?

( https://i.stack.imgur.com/Sy9Wn.jpg )

You can move it new excel file or extract using pandas module in python

import pandas as pd
df=pd.read_excel("your file name", header=None)#In my case my excel donot have 1st line as column names so i have added `header=None` parameter, if you have 1st line in excel as a columns names you can remove it
df1=df[[2,3]]
'''
in my case my excel file contains 
>>> df
   0  1  2  3
0  1  2  3  4
1  8  7  6  5
2  9  1  2  3
3  7  6  5  4

Here df is the data frame. Pandas will load excel file like data frame 
where my 1st row is my column names i.e 1,2,3,4 
So after assigning specific columns(2,3) to df1
new df1 will be like
   2  3
0  7  6
1  1  2
2  6  5
which is further moved to excel file
''' 
df1.to_excel('output.xlsx',index=False)#output.xlsx contains specified columns only

Hope the solution will be helpful for easy retrieval of excel only for particular columns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM