openpyxl,处理大型 excel 文件
openpyxl, handle large exel files
我使用openpyxl进行数据处理。
第一次,我将数据复制代码文件写入文件(xlsx -> xlsx)进行测试。
# open input file
wb = load_workbook(filename='input.xlsx', read_only=True)
ws = wb['sheet name']
# create output file
out = Workbook(write_only=True)
out_sh = out.create_sheet('sheet name')
# copy data
for rows in ws:
out_sh.append(cells.value for cells in rows)
# save file
out.save('output.xlsx')
wb.close()
out.close()
input file size is 394 MB and there is 6 sheets.
5 sheets size is 1048576 rows by 17 (A~Q) columns.
My memory size is 8 GB and normally 66% in use (idle state, about 2.5 GB left).
last one sheet size is small. i tested for one large sheets.
在 openpyxl 中,我使用 read_only 和 write_only 选项进行优化,但是当我 运行 只有 1 sheet(不是整个 394MB 文件)的数据复制代码,我得到一个 MemoryError.
如果添加数据分析代码,将只能处理较小的文件。
有没有我还没有尝试过的大文件处理优化技术?
还有其他线程有同样的错误问题:
Memory Error Thread 1
Memory Error Thread 2
它对您的问题有帮助吗?
我使用openpyxl进行数据处理。
第一次,我将数据复制代码文件写入文件(xlsx -> xlsx)进行测试。
# open input file
wb = load_workbook(filename='input.xlsx', read_only=True)
ws = wb['sheet name']
# create output file
out = Workbook(write_only=True)
out_sh = out.create_sheet('sheet name')
# copy data
for rows in ws:
out_sh.append(cells.value for cells in rows)
# save file
out.save('output.xlsx')
wb.close()
out.close()
input file size is 394 MB and there is 6 sheets.
5 sheets size is 1048576 rows by 17 (A~Q) columns.
My memory size is 8 GB and normally 66% in use (idle state, about 2.5 GB left).
last one sheet size is small. i tested for one large sheets.
在 openpyxl 中,我使用 read_only 和 write_only 选项进行优化,但是当我 运行 只有 1 sheet(不是整个 394MB 文件)的数据复制代码,我得到一个 MemoryError.
如果添加数据分析代码,将只能处理较小的文件。
有没有我还没有尝试过的大文件处理优化技术?
还有其他线程有同样的错误问题:
Memory Error Thread 1 Memory Error Thread 2
它对您的问题有帮助吗?