# -*- coding:utf8 -*- import pandas as pd file_name = '查询银行汇总_20w.xlsx' file_name_prefix = file_name.split('.')[0] df = pd.DataFrame(pd.read_excel(file_name)) # 每个文件的行数 file_num = 35000 # 共分成多少个文件 sheet_num = float(df.shape[0] / file_num) print(sheet_num) if int(sheet_num) < sheet_num: sheet_num2 = int(sheet_num) + 1 else: sheet_num2 = int(sheet_num) print(sheet_num2) for i in range(1, sheet_num2 + 1): if i == 0: df.iloc[(i - 1) * file_num: i * file_num].to_excel(file_name_prefix + f'{i}.xlsx', index=False) print("0" + str(i)) elif i <= sheet_num2: df.iloc[(i - 1) * file_num: i * file_num].to_excel(file_name_prefix + f'{i}.xlsx', index=False) print("1" + str(i)) # 万一有余数或者不够,所以最后一个文件读到最后 else: df.iloc[(i - 1) * file_num:].to_excel(file_name_prefix + f'{i}.xlsx', index=False) print("2" + str(i))
标签:分成,sheet,name,num2,excel,num,file From: https://www.cnblogs.com/daizichuan/p/17488823.html