I have a CSV file with 100 rows.
How do I read specific rows?
I want to read say the 9th line or the 23rd line etc?
You could use a list comprehension to filter the file like so:
list comprehension
with open('file.csv') as fd: reader=csv.reader(fd) interestingrows=[row for idx, row in enumerate(reader) if idx in (28,62)] # now interestingrows contains the 28th and the 62th row after the header
2.1m questions
2.1m answers
60 comments
57.0k users