pandas.tseries.offsets.BusinessHour#

class pandas.tseries.offsets.BusinessHour#

DateOffset 子类,表示可能的 n 个工作小时。

参数:
nint, default 1

所表示的小时数。

normalizebool,默认为 False

在生成日期范围之前将 start/end 日期规范化为午夜。

startstr, time, 或 list of str/time, 默认值 “09:00”

自定义工作小时的开始时间,24小时制。

endstr, time, 或 list of str/time, 默认值: “17:00”

自定义工作小时的结束时间,24小时制。

offsettimedelta, default timedelta(0)

要应用的日期偏移量。

示例

您可以使用参数 n 来表示移动 n 小时。

>>> ts = pd.Timestamp(2022, 12, 9, 8)
>>> ts + pd.offsets.BusinessHour(n=5)
Timestamp('2022-12-09 14:00:00')

您也可以更改工作时间的开始和结束时间。

>>> ts = pd.Timestamp(2022, 8, 5, 16)
>>> ts + pd.offsets.BusinessHour(start="11:00")
Timestamp('2022-08-08 11:00:00')
>>> from datetime import time as dt_time
>>> ts = pd.Timestamp(2022, 8, 5, 22)
>>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0))
Timestamp('2022-08-08 10:00:00')

将参数 normalize 设置为 True,会将下一个工作小时的开始时间移动到午夜。

>>> ts = pd.Timestamp(2022, 12, 9, 8)
>>> ts + pd.offsets.BusinessHour(normalize=True)
Timestamp('2022-12-09 00:00:00')

您可以将工作日的小时划分为几个部分。

>>> import datetime as dt
>>> freq = pd.offsets.BusinessHour(start=["06:00", "10:00", "15:00"],
...                                end=["08:00", "12:00", "17:00"])
>>> pd.date_range(dt.datetime(2022, 12, 9), dt.datetime(2022, 12, 13), freq=freq)
DatetimeIndex(['2022-12-09 06:00:00', '2022-12-09 07:00:00',
               '2022-12-09 10:00:00', '2022-12-09 11:00:00',
               '2022-12-09 15:00:00', '2022-12-09 16:00:00',
               '2022-12-12 06:00:00', '2022-12-12 07:00:00',
               '2022-12-12 10:00:00', '2022-12-12 11:00:00',
               '2022-12-12 15:00:00', '2022-12-12 16:00:00'],
               dtype='datetime64[ns]', freq='bh')

属性

base

Returns a copy of the calling offset object with n=1 and all other attributes equal.

calendar

返回用于营业日计算的日历。

end

Return the end time(s) of the business hour.

freqstr

Return a string representing the frequency.

holidays

返回用于自定义营业日计算的节假日。

kwds

Return a dict of extra parameters for the offset.

n

Return the count of the number of periods.

name

Return a string representing the base frequency.

nanos

Returns an integer of the total number of nanoseconds for fixed frequencies.

next_bday

用于移动到下一个工作日。

normalize

Return boolean whether the frequency can align with midnight.

偏移量

self._offset 的别名。

rule_code

Return a string representing the base frequency.

start

Return the start time(s) of the business hour.

weekmask

返回用于自定义营业日计算的周掩码。

Methods

copy()

Return a copy of the frequency.

is_month_end(ts)

Return boolean whether a timestamp occurs on the month end.

is_month_start(ts)

Return boolean whether a timestamp occurs on the month start.

is_on_offset(dt)

Return boolean whether a timestamp intersects with this frequency.

is_quarter_end(ts)

Return boolean whether a timestamp occurs on the quarter end.

is_quarter_start(ts)

Return boolean whether a timestamp occurs on the quarter start.

is_year_end(ts)

Return boolean whether a timestamp occurs on the year end.

is_year_start(ts)

Return boolean whether a timestamp occurs on the year start.

rollback(other)

Roll provided date backward to next offset only if not on offset.

rollforward(other)

Roll provided date forward to next offset only if not on offset.