Count how many records are in a CSV Python?

后端 未结 16 1487
无人共我
无人共我 2020-11-29 16:43

I\'m using python (Django Framework) to read a CSV file. I pull just 2 lines out of this CSV as you can see. What I have been trying to do is store in a variable the total n

16条回答
  •  日久生厌
    2020-11-29 17:34

    when you instantiate a csv.reader object and you iter the whole file then you can access an instance variable called line_num providing the row count:

    import csv
    with open('csv_path_file') as f:
        csv_reader = csv.reader(f)
        for row in csv_reader:
            pass
        print(csv_reader.line_num)
    

提交回复
热议问题