Count how many records are in a CSV Python?

后端 未结 16 1495
无人共我
无人共我 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:40

    import csv
    count = 0
    with open('filename.csv', 'rb') as count_file:
        csv_reader = csv.reader(count_file)
        for row in csv_reader:
            count += 1
    
    print count
    

提交回复
热议问题