我在excel上有超过20,000行数据,并希望将数据与A列部分分开以表示F列。如何使用python做到这一点?
答案 0 :(得分:0)
您可以将其移动到新的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