Python reads the CSV file (how CSV.DictReader ()) looks up a column of values

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)

Feb.27,2021

your file should be open and then read . My following example works well with work

-sharp!/usr/bin/python

import csv

filename = './a.csv'
  
duration_list = []
with open(filename) as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        duration_list.append(row['duration'])


print duration_list
Menu