簡體   English   中英

使用Python在Excel中將部分數據從一列移動到另一列

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

我在excel上有超過20,000行數據,並希望將數據與A列部分分開以說F列。如何使用python做到這一點?

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

您可以將其移動到新的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

希望該解決方案將對僅針對特定列的excel輕松檢索有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM