Python: any lazy method for reading .xls files?

Viewed 43

I know how to read .xls files with pandas. However, it returns all the data. I want to load data on demand, I mean, I want a generator that returns the next row each time is iterated. See this question for general files.

I know openpyxl can do this, following this webpage. However, it doesn't support old .xls files. It recommends me to use xlrd, however, I don't know how to do what I want with that package.

The documentation tells how to do that sheet by sheet, but not row by row (my file has only one sheet).

1 Answers

Pandas doesn't support lazy loading, it reads the file and keeps everything in memory.

Polars -- an alternative to pandas -- supports lazy loading.
Unfortunately this isn't yet implemented for xls files.

One solution is to convert the excel file to csv and use the scan_csv function.

import polars as pl
pl.scan_csv("sample.csv")
<polars.internals.lazyframe.frame.LazyFrame object at 0x7f0ae95d1c00>
Related