适用条件
1:excel表比较多
2:excel的数据量比较大,不然的话excel筛选&手动合并还是很舒服滴~
需求
取出【电话】列中不为空所对应的行的值并且将几张表给合并起来
来来来,放代码了!!
import xlrd
import pandas as pd
import openpyxl
target_xls = "合并表1.xlsx"
source_xls = ["全1.xlsx", "全2.xlsx","全3.xlsx",\
"全4.xlsx","全5.xlsx","全6.xlsx"]
sysptoms=pd.DataFrame()
for i in range(len(source_xls)):
print(i)#了解打印进度
sheet2=pd.read_excel(source_xls[i]).fillna("")#有空格,填充函数,填的空值。要加fillna,不然无法删除空值所对应的行
sysptom = sheet2[sheet2['电话'] !=""]#筛选
sysptoms=pd.concat([sysptoms,sysptom])#两个dataframe合并,相当于合并excel
print(type(sysptom))
sysptoms.to_excel(target_xls, index=False)#pandas写入excel用.to_excel
print("ok&