基于24小时时钟减去2个时间戳?

2024-04-18 18:43:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个df看起来像

         Date               Time 
2019-07-23 21:17:47.599  22:00:00.000
2019-07-23 21:11:46.973  21:50:00.000

我使用以下代码创建时间差值列

 df3['NEW'] = ((pd.to_timedelta(df3.Time.astype(str))- 
  pd.to_timedelta(df3.order_created_time_local.dt.strftime('%H:%M:%S'))) /
                 np.timedelta64(1, 'm'))

下面是我得到的,需要的列是我想要的值:

Date                               Time      Difference      Needed
2019-08-21 21:57:28.721      21:30:00.000   -19.883333     -19.883333
2019-08-21 22:16:57.795      04:00:00.000   -1096.950000.    420.000
2019-08-21 21:00:00.00       21:30:00.000      30.000        30.000

因为在24小时制中,04:00:00.000将是凌晨4:00,22:16将是晚上10:16,有没有一种方法可以在此基础上计算出正确的分差?你知道吗

细节:时间代表任何一天的时间。就像商店关门时间一样。不需要日期只需要一个时间,差应该只是实际分钟数与时间-日期的差(日期中的时间不需要实际日期)

谢谢!你知道吗


Tags: to代码dfnewdatetime时间order