我在电子表格中有一个数据集,基本上是纽约地铁每趟火车的数据。
╔═══════╦══════╦══════════════╦════════════════╦═════════╦═══════════════╦══════════════════╗
║ trip ║ id ║ arrival_time ║ departure_time ║ stop_id ║ stop_sequence ║ Station ║
╠═══════╬══════╬══════════════╬════════════════╬═════════╬═══════════════╬══════════════════╣
║ GO505 ║ 20_2 ║ 0:06:00 ║ 0:06:00 ║ 237 ║ 1 ║ Penn Station ║
║ GO505 ║ 20_2 ║ 0:18:00 ║ 0:18:00 ║ 214 ║ 2 ║ Woodside ║
║ GO505 ║ 20_2 ║ 0:23:00 ║ 0:23:00 ║ 55 ║ 3 ║ Forest Hills ║
║ GO505 ║ 20_2 ║ 0:25:00 ║ 0:25:00 ║ 107 ║ 4 ║ Kew Gardens ║
║ GO505 ║ 20_2 ║ 0:29:00 ║ 0:32:00 ║ 102 ║ 5 ║ Jamaica ║
║ GO505 ║ 20_2 ║ 0:47:00 ║ 0:47:00 ║ 183 ║ 6 ║ Rockville Centre ║
║ GO505 ║ 20_2 ║ 0:50:00 ║ 0:50:00 ║ 225 ║ 7 ║ Baldwin ║
║ GO505 ║ 20_2 ║ 0:53:00 ║ 0:53:00 ║ 64 ║ 8 ║ Freeport ║
║ GO505 ║ 20_2 ║ 0:56:00 ║ 0:56:00 ║ 226 ║ 9 ║ Merrick ║
║ GO505 ║ 20_2 ║ 0:59:00 ║ 0:59:00 ║ 16 ║ 10 ║ Bellmore ║
║ GO505 ║ 20_2 ║ 1:02:00 ║ 1:02:00 ║ 215 ║ 11 ║ Wantagh ║
║ GO505 ║ 20_2 ║ 1:05:00 ║ 1:05:00 ║ 187 ║ 12 ║ Seaford ║
║ GO505 ║ 20_2 ║ 1:07:00 ║ 1:07:00 ║ 136 ║ 13 ║ Massapequa ║
║ GO505 ║ 20_2 ║ 1:09:00 ║ 1:09:00 ║ 135 ║ 14 ║ Massapequa Park ║
║ GO505 ║ 20_2 ║ 1:12:00 ║ 1:12:00 ║ 8 ║ 15 ║ Amityville ║
║ GO505 ║ 20_2 ║ 1:15:00 ║ 1:15:00 ║ 38 ║ 16 ║ Copiague ║
║ GO505 ║ 20_2 ║ 1:18:00 ║ 1:18:00 ║ 117 ║ 17 ║ Lindenhurst ║
║ GO505 ║ 20_2 ║ 1:23:00 ║ 1:23:00 ║ 27 ║ 18 ║ Babylon ║
║ GO505 ║ 20_3 ║ 1:00:00 ║ 1:00:00 ║ 27 ║ 1 ║ Babylon ║
║ GO505 ║ 20_3 ║ 1:05:00 ║ 1:05:00 ║ 117 ║ 2 ║ Lindenhurst ║
║ GO505 ║ 20_3 ║ 1:08:00 ║ 1:08:00 ║ 38 ║ 3 ║ Copiague ║
║ GO505 ║ 20_3 ║ 1:10:00 ║ 1:10:00 ║ 8 ║ 4 ║ Amityville ║
║ GO505 ║ 20_3 ║ 1:13:00 ║ 1:13:00 ║ 135 ║ 5 ║ Massapequa Park ║
╚═══════╩══════╩══════════════╩════════════════╩═════════╩═══════════════╩══════════════════╝
我需要根据stop_sequence中的序列将其分成某些部分。从1到n(此处为18)的每个序列表示火车旅行1次。因此,例如,我需要为每次旅行计算每次旅行的时间(这是每个最后一次stop_sequence的出发时间-第一个stop_sequence的到达时间)(大约有5,000个)。我该怎么做呢?我希望我可以将python中带有熊猫的列拆分为多个行程,并计算每次行程的时间。但是我不知道该怎么做。
我的预期输出是
行程ID trip行程时间
GO505 20_2║x:xx:xx
GO505 20_3║x:xx:xx
我是数据科学领域的新手。请帮助!
我的例如(范围A:G->有关火车每次行程的数据)
单元格I1: =QUERY({ArrayFormula(A:A&" "&B:B),ArrayFormula(VALUE(C:D))},"select Col1,max(Col3)-min(Col2) where Col1!=' ' group by Col1 label max(Col3)-min(Col2) 'Duration of the trip' format max(Col3)-min(Col2) 'hh:mm:ss'")
功能参考