I use CSV"s dictreader () to read the CSV file. I want to put the value of the "duration" column in the file into the list duration_list, but the error after running is as follows:
the following is the code section:
def count_duration (filename,city):
summary_reader = csv.DictReader(filename)
duration_list = []
for row in summary_reader:
duration_list.append(row["duration"])
total_duration = 0
total_number = 0
for i in duration_list:
total_duration += i
total_number += 1
average_duration = total_duration / total_number
more_than_thirty = len(x for x in duration_list if x>30) / len(duration_list)
return "{}{}30{}".format(city,average_duration,more_than_thirty)
data_file = {"Washington":". / data/Washington-2016-Summary.csv",
"Chicago": "./data/Chicago-2016-Summary.csv",
"NYC": "./data/NYC-2016-Summary.csv"}
for city, filename in data_file.items ():
count_duration(filename,city)