您可以使用
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
您可以使用
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