business hour.php,在Pandas中结合CustomBusinessDay和BusinessHour课程

从版本0.18.1开始,您可以使用^{}:The CustomBusinessHour is a mixture of BusinessHour and

CustomBusinessDay which allows you to specify arbitrary holidays. For

details, see Custom Business Hour (GH11514)In [1]: from pandas.tseries.offsets import CustomBusinessHour

In [2]: from pandas.tseries.holiday import USFederalHolidayCalendar

In [3]: bhour_us = CustomBusinessHour(calendar=USFederalHolidayCalendar())

Friday before MLK Day

In [4]: dt = datetime(2014, 1, 17, 15)

In [5]: dt + bhour_us

Out[5]: Timestamp('2014-01-17 16:00:00')

Tuesday after MLK Day (Monday is skipped because it’s a holiday)

In [6]: dt + bhour_us * 2

Out[6]: Timestamp('2014-01-21 09:00:00')

我使用的一个例子是from pandas.tseries.offsets import CustomBusinessHour

from pandas.tseries.holiday import Holiday, AbstractHolidayCalendar

class MyCalendar(AbstractHolidayCalendar):

rules = [Holiday('my birthday', month=6, day=6)]

cbh = CustomBusinessHour(2, start='10:00', end='16:00', calendar=MyCalendar())

pd.date_range('20170602', periods=20, freq=cbh)

Out:

DatetimeIndex(['2017-06-02 10:00:00', '2017-06-02 12:00:00',

'2017-06-02 14:00:00', '2017-06-05 10:00:00',

'2017-06-05 12:00:00', '2017-06-05 14:00:00',

'2017-06-07 10:00:00', '2017-06-07 12:00:00',

'2017-06-07 14:00:00', '2017-06-08 10:00:00',

'2017-06-08 12:00:00', '2017-06-08 14:00:00',

'2017-06-09 10:00:00', '2017-06-09 12:00:00',

'2017-06-09 14:00:00', '2017-06-12 10:00:00',

'2017-06-12 12:00:00'],

dtype='datetime64[ns]', freq='2CBH')

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值