遍历dataframe
import pandas as pd import os if __name__ == '__main__': Folder_Path = 'c:\checklog' os.chdir(Folder_Path) file_list = os.listdir() writer = pd.ExcelWriter('c:\shuju\out.xlsx') list = [] for item in file_list: file_path = os.path.join(Folder_Path, item) df = pd.read_excel(file_path, sheet_name=0) for index, row in df.iterrows(): if isinstance(row['核查说明'], str): list.append(row) df2 = pd.DataFrame(list) df2.to_excel(writer, sheet_name='sheet1') writer.save()