CSV read specific row

后端 未结 5 786
鱼传尺愫
鱼传尺愫 2020-12-03 07:27

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?

5条回答
  •  我在风中等你
    2020-12-03 08:04

    You could read all of them and then use normal lists to find them.

    with open('bigfile.csv','rb') as longishfile:
        reader=csv.reader(longishfile)
        rows=[r for r in reader]
    print row[9]
    print row[88]
    

    If you have a massive file, this can kill your memory but if the file's got less than 10,000 lines you shouldn't run into any big slowdowns.

提交回复
热议问题