Is there a function in Python/Pandas to get business time Delta between two date times?

时光怂恿深爱的人放手 提交于 2019-12-11 06:05:47

问题


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.

Thanks,

Nick


回答1:


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)


来源:https://stackoverflow.com/questions/43835273/is-there-a-function-in-python-pandas-to-get-business-time-delta-between-two-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!