def duration_in_mins(datum, city):
if city == 'Washington':
duration = round(int(datum['Duration (ms)']) /60000, 4)
else:
duration = round(int(datum['tripduration']) /60 ,4)
return duration
Но после вызова этой функции это дает мне ключевую ошибку
def condense_data(in_file, out_file, city):
with open(out_file, 'w') as f_out, open(in_file, 'r') as f_in:
out_colnames = ['duration', 'month', 'hour', 'day_of_week', 'user_type']
trip_writer = csv.DictWriter(f_out, fieldnames = out_colnames)
trip_writer.writeheader()
trip_reader =csv.DictReader(in_file)
for row in trip_reader:
new_point = {}
dur=duration_in_mins(row, city)
month,hour, day_of_week=time_of_trip(row, city)
type=type_of_user(row, city)
new_point={'duration':dur, 'month':month, 'hour':hour, 'day_of_week':day_of_week, 'user_type':type}
trip_writer.writerow(**new_point)
После успешной компиляции функции конденсата_данных, когда я проверяю, работает ли она или нет, я обнаружил, чтоэто дает мне ключевую ошибку
KeyError: 'Duration (ms)'