import os import pandas as pd folder_path = r''#配置你自己的文件夹路径eg:C:\Users\86159\Desktop\项目管理论文 excel_path = r""#配置你自己的名单路径eg:D:\user\班级资料\名单.xlsx files_in_folder = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))] df = pd.read_excel(excel_path) df['是否包含'] = '否' for index, row in df.iterrows(): name_to_check = row['Name'] # 在你的Excel中创建一个名为'Name'的列,否则这一行会报错 for file in files_in_folder: if name_to_check in file: df.at[index, '是否包含'] = '是' break for index, row in df.iterrows(): if row['是否包含'] == '否': print(row['Name'])