I'm writing an Alexa skill to tell me when the next buses are due to take me to work. I have reached a point where I have a pandas dataframe with the necessary information. It looks like this:
BusStop 1st 2nd 3rd 4th 5th BusLine
10 myStop 20:05 20:16 20:28 20:38 20:52 A
3 myStop 16:07 17:07 18:13 19:12 20:12 E
15 myStop 18:26 18:36 18:46 18:58 19:25 K
But I want to transform it to include only earliest times so Alexa can tell me "The A bus is coming in 5 minutes, the K bus in 20 minutes" or something to that effect.
BusStop 1st BusLine
10 myStop 16:07 E
3 myStop 17:07 E
15 myStop 18:13 E
I have a way of doing this but it seems quite clumsy and wondered if there is a better way to do this. I have it working with the below code:
ranked_buses_to_work = pd.DataFrame()
for i in [ '1st','2nd','3rd','4th','5th']:
temp_df = buses_to_work_df[['BusStop', i, 'BusLine']]
temp_df.columns = ['BusStop', 'BusTime', 'BusLine']
ranked_buses_to_work = ranked_buses_to_work.append(temp_df)
ranked_buses_to_work = ranked_buses_to_work .sort_values(by=['BusTime'], inplace=True)
Is there a better way to do this?