# converting input time value to datetime.
def conv_time(time_val):
if pd.isnull(time_val):
return np.nan
else:
# replace 24:00 o'clock with 00:00 o'clock:
if time_val == 2400: time_val = 0
# creating a 4 digit value out of input value:
time_val = "{0:04d}".format(int(time_val))
# creating a time datatype out of input value:
time_formatted = datetime.time(int(time_val[0:2]), int(time_val[2:4]))
return time_formatted
#Example on how to use our function:
df['ARRIVAL_TIME'] = df['ARRIVAL_TIME'].apply(conv_time)
df['DEPARTURE_TIME'] = df['DEPARTURE_TIME'].apply(conv_time)