咔片PPT · AI自动生成演示文稿,模板丰富、排版精美 讯飞智文 · 一键生成PPT和Word,高效应对学习与办公

使用背景:使用python批量下载链接时,只有一个表格,有180万数据,下载太慢。将表格分割成多个表,开启多个脚本跑代码。原来一个脚本跑,跑了一天,才下了20万数据。现在20个脚本跑,2天不到就跑完了。

def cut_excel(): #表名 df = pd.read_excel('excek.xlsx') rows, cols = df.shape print(rows, cols) print(len(df)) print(df.head()) #分割之后每张表有9万数据 split_num = 90000 value = math.floor(rows / split_num) print(value) rows_format = value * split_num print(rows_format) new_list = [[i, i+split_num] for i in range(0, rows_format, split_num)] for i_j in new_list: i, j = i_j excel_small = df[i:j] excel_small.to_excel('excel_{0}_{1}.xlsx'.format(i, j), index=False) df[rows_format:].to_excel('excel_last.xlsx')