Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read a full excel file chunk by chunk using pandas

Tags:

python

pandas

what is quickest way to read a file chunk by chunk in pandas: I am doing something like this which I found on stackoverflow as well . but how I will keep track of skiprow and skip footer if my file rows are for example like 1000 ?

# if the file contains 300 rows, this will read the middle 100
df = pd.read_excel('/path/excel.xlsx', skiprows=100, skip_footer=100)
like image 496
TNN Avatar asked Oct 19 '25 10:10

TNN


1 Answers

You could use range. Assuming you want to process chunks of 100 lines in in 1000 lines excel file:

total = 1000
chunksize = 100
for skip in range(0, total, chunksize):
    df = pd.read_excel('/path/excel.xlsx', skiprows=skip, nrows=chunksize)
    # process df
    ...
like image 200
Serge Ballesta Avatar answered Oct 22 '25 02:10

Serge Ballesta