I am reading a large csv file in chunks as I don’t have enough memory to store. I would like to read its first 10 rows (0 to 9 rows), skip the next 10 rows(10 to 19), then read the next 10 rows( 20 to 29 rows), again skip the next 10 rows(30 to 39) and then read rows from 40 to 49 and so on. Following is the code I am using:
#initializing n1 and n2 variable
n1=1
n2=2
#reading data in chunks
for chunk in pd.read_csv('../input/train.csv',chunksize=10, dtype=dtypes,skiprows=list(range( ((n1*10)+1), ((n2*10) +1) ))):
sample_chunk=chunk
#displaying the sample_chunk
print(sample_chunk)
#incrementing n1
n1=n1+2
#incrementing n2
n2=n2+2
However, the code does not work as I assume I have designed. It only skip rows from 10 to 19 (i.e: It reads rows from 0 to 9, skip 10 to 19, then reads 20 to 29, then again read 30 to 39, then again read 40 to 49, and keep on reading all the rows). Please help me identify what I am doing wrong.