简体   繁体   English

使用Python在Excel中将部分数据从一列移动到另一列

[英]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? 我在excel上有超过20,000行数据,并希望将数据与A列部分分开以说F列。如何使用python做到这一点?

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

You can move it new excel file or extract using pandas module in python 您可以将其移动到新的Excel文件或使用python中的pandas模块提取

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 希望该解决方案将对仅针对特定列的excel轻松检索有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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