Olá pessoal, tudo jóia?
Eu tenho um df que preciso calcular a diferença entre duas datas, porém essa diferença preciso que seja em horas, tipo:
envio_os hora_chegada intervalo
2022-01-01 22:31:00 2022-01-01 23:48:00 0 days 01:17:00
2022-01-01 03:50:00 2022-01-01 04:30:00 0 days 00:40:00
2022-01-01 07:57:00 2022-01-01 09:59:00 0 days 02:02:00
2022-01-01 11:42:00 2022-01-01 13:47:00 0 days 02:05:00
2022-01-01 12:35:00 2022-01-01 12:55:00 0 days 00:20:00
2022-01-01 14:27:00 2022-01-01 15:03:00 0 days 00:36:00
2022-01-01 17:18:00 2022-01-01 17:52:00 0 days 00:34:00
2022-01-01 21:29:00 2022-01-01 21:42:00 0 days 00:13:00
2022-01-01 22:10:00 2022-01-01 22:32:00 0 days 00:22:00
2022-01-01 22:50:00 2022-01-01 23:40:00 0 days 00:50:00
Essa coluna intervalo, consegui fazer por cálculo usando o pandas, mas ela vem com esse 0 days antes e eu gostaria que ele não vinhesse, mas sim da seguinte forma:
envio_os hora_chegada intervalo
2022-01-01 22:31:00 2022-01-01 23:48:00 01:17:00
2022-01-01 03:50:00 2022-01-01 04:30:00 00:40:00
2022-01-01 07:57:00 2022-01-01 09:59:00 02:02:00
2022-01-01 11:42:00 2022-01-01 13:47:00 02:05:00
2022-01-01 12:35:00 2022-01-01 12:55:00 00:20:00
2022-01-01 14:27:00 2022-01-01 15:03:00 00:36:00
2022-01-01 17:18:00 2022-01-01 17:52:00 00:34:00
2022-01-01 21:29:00 2022-01-01 21:42:00 00:13:00
2022-01-01 22:10:00 2022-01-01 22:32:00 00:22:00
2022-01-01 22:50:00 2022-01-01 23:40:00 00:50:00
Mas pra além disso, se eu tiver um serviço que passe de 24 horas, quero que ele retorne apenas o tempo tbm, da seguinte forma:
envio_os hora_chegada intervalo
2022-01-01 22:31:00 2022-01-03 23:48:00 49:17:00
Para me ajudarem, deixo aqui um exemplo com esse dataframe:
import pandas as pd
df = pd.DataFrame({'envio':['2022-01-01 22:31:00','2022-01-01 03:50:00', '2022-01-01 22:31:00'],
'chegada': ['2022-01-01 23:48:00','2022-01-01 04:30:00','2022-01-03 23:48:00']})
df['intervalo'] = pd.to_datetime(df['chegada']) - pd.to_datetime(df['envio'])