I have a dataset with rows like this:
I would like to apply my function to each row where air_time is NaN so that I can set the air_time depending on what the departure and arrival time is. How would I go around this?
def get_air_time(dep_time, arr_time):
converted_dep_time = datetime.timedelta(minutes=(dep_time // 100) * 60 (dep_time % 100))
converted_arr_time = datetime.timedelta(minutes=(arr_time // 100) * 60 (arr_time % 100))
delta = converted_arr_time - converted_dep_time
return abs(delta.total_seconds() / 60)
CodePudding user response:
Please try this:
df['air_time'] = df[['dep_time', 'arr_time']].apply(get_air_time, axis=1)