import itertools
i, j = 10, 20
with open(trainFile, 'rt') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in itertools.islice(spamreader, i, j + 1):
    pass
How to loop through specific range of rows with Python csv reader?