import pandas as pd from openpyxl import workbook data = pd.read_excel("C:\\Users\\yxb\\Downloads\\待处理.xlsx") rows = data.shape[0] #获取行数 shape[1]获取列数 department_list = [] for i in range(rows): temp = data["单位"][i] if temp not in department_list: department_list.append(temp) #列表存储 for department in department_list: new_df = pd.DataFrame() for i in range (0, rows): if data["单位"][i] == department: new_df = pd.concat([new_df, data.iloc[[i],:]], axis = 0, ignore_index = True) new_df.to_excel(str(department)+".xls", sheet_name=department, index = False) #将每个销售部门存成一个新excel