这样试试?import pandas as pd
import os,re
path=r'D:\python\test\样例'
p=re.compile('\w+苹果')
def find_apple(x):
if len(p.findall(x['名称']))>0:
return 1
else:
return 0
def check_apple(data):
data['flag'] = data.apply(find_apple, axis=1)
data = data[data['flag'].isin(['1'])]
return data
zhangsan=pd.read_excel(os.path.join(path,'张三.xlsx'))
zhangsan=check_apple(zhangsan)
print(zhangsan)
lisi=pd.read_excel(os.path.join(path,'李四.xlsx'))
lisi=check_apple(lisi)
print(lisi)
wangwu=pd.read_excel(os.path.join(path,'王五.xlsx'))
wangwu=check_apple(wangwu)
print(wangwu)
result=pd.concat([zhangsan,lisi,wangwu])
result=result.iloc[:,:-1]
print(result)
result.to_excel(os.path.join(path,'result.xlsx'),index=False)
|