pandas.tseries.offsets.BusinessHour#

classpandas.tseries.offsets.BusinessHour#

DateOffset subclass representing possibly n business hours.

Parameters:
nint, default 1

The number of hours represented.

normalizebool, default False

Normalize start/end dates to midnight before generating date range.

startstr, time, or list of str/time, default "09:00"

Start time of your custom business hour in 24h format.

endstr, time, or list of str/time, default: "17:00"

End time of your custom business hour in 24h format.

offsettimedelta, default timedelta(0)

Time offset to apply.

Examples

You can use the parameter n to represent a shift of n hours.

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

You can also change the start and the end of business hours.

>>> 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')

Passing the parameter normalize equal to True, you shift the start of the next business hour to midnight.

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

You can divide your business day hours into several parts.

>>> 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')

Attributes

base

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

end

freqstr

Return a string representing the frequency.

kwds

Return a dict of extra parameters for the offset.

n

name

Return a string representing the base frequency.

next_bday

Used for moving to next business day.

offset

Alias for self._offset.

Methods

copy()

Return a copy of the frequency.

is_anchored()

(DEPRECATED) Return boolean whether the frequency is a unit frequency (n=1).

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.