how to sum a column in csv python using list in python

Solutions on MaxInterview for how to sum a column in csv python using list in python by the best coders in the world

showing results for - "how to sum a column in csv python using list in python"
Winston
17 Jun 2019
1import csv
2csv_file = csv.reader(open("your_file_name.csv"))
3
4dist = 0
5for row in csv_file:
6    _dist = row[2]
7    try: 
8        _dist = float(_dist)
9    except ValueError:
10        _dist = 0
11
12    dist += _dist
13