使用python读取大xlsx文件的一部分 [英] Reading a portion of a large xlsx file with python

查看:62
本文介绍了使用python读取大xlsx文件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的.xlsx文件,具有一百万行.我不想一次性打开整个文件.我想知道是否可以读取文件的一部分,对其进行处理,然后再读取下一块? (我更喜欢用熊猫.)

I have a large .xlsx file with 1 million rows. I don't want to open the whole file in one go. I was wondering if I can read a chunk of the file, process it and then read the next chunk? (I prefer to use pandas for it.)

推荐答案

是.熊猫支持分块阅读.您将像这样读取Excel文件.

Yes. Pandas supports chunked reading. You would go about reading an excel file like so.

import pandas as pd
xl = pd.ExcelFile("myfile.xlsx")
for sheet_name in xl.sheet_names:
  reader = xl.parse(sheet_name, chunksize=1000):
  for chunk in reader:
    #parse chunk here

这篇关于使用python读取大xlsx文件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆