Python/Pandas中是否有一个函数可以获取两个日期时间之间的营业时间增量? [英] Is there a function in Python/Pandas to get business time Delta between two date times?

查看:225
本文介绍了Python/Pandas中是否有一个函数可以获取两个日期时间之间的营业时间增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个datetime列的pandas数据框,我想在工作时间"中计算列之间的时间增量.使用offsets方法添加业务时间增量很容易,但是我似乎找不到内置的东西可以在工作日,小时,分钟,秒内返回时间增量.我是Python的新手,所以很可能我缺少了一些东西.

I've got a pandas dataframe with two datetime columns and I would like to calculate the timedelta between the columns in "business minutes". It's easy to add business timedeltas using the offsets method, but I can't seem to find something built in that returns a timedelta in business days, hours, minutes, seconds. I'm very new to Python so it's very likely I'm missing something.

谢谢

尼克

推荐答案

我认为numpy/pandas中没有办法,但是您可以使用python lib

I don't think there's a way in numpy/pandas, but you can do it with python lib businesstime:

>>> datetime(2013, 12, 26, 5) - datetime(2013, 12, 23, 12)
datetime.timedelta(2, 61200)
>>> bt = businesstime.BusinessTime(holidays=businesstime.holidays.usa.USFederalHolidays())
>>> bt.businesstimedelta(datetime(2013, 12, 23, 12), datetime(2013, 12, 26, 5))
datetime.timedelta(1, 18000)

这篇关于Python/Pandas中是否有一个函数可以获取两个日期时间之间的营业时间增量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆