我有一个包含100行的CSV文件。
如何读取特定行?
我想读第9行或第23行等?
您可以使用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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句