pandas.tseries.offsets.CustomBusinessMonthBegin#

classpandas.tseries.offsets.CustomBusinessMonthBegin#

DateOffset subclass representing custom business month(s).

Increments between beginning of month dates.

Parameters:
nint, default 1

The number of months represented.

normalizebool, default False

Normalize start dates to midnight before generating date range.

weekmaskstr, Default ‘Mon Tue Wed Thu Fri’

Weekmask of valid business days, passed to numpy.busdaycalendar.

holidayslist

List/array of dates to exclude from the set of valid business days, passed to numpy.busdaycalendar.

calendarnp.busdaycalendar

Calendar to integrate.

offsettimedelta, default timedelta(0)

Time offset to apply.

See also

DateOffset

Standard kind of date increment.

Examples

In the example below we use the default parameters.

>>> ts = pd.Timestamp(2022, 8, 5)
>>> ts + pd.offsets.CustomBusinessMonthBegin()
Timestamp('2022年09月01日 00:00:00')

Custom business month start can be specified by weekmask parameter. To convert the returned datetime object to its string representation the function strftime() is used in the next example.

>>> importdatetimeasdt
>>> freq = pd.offsets.CustomBusinessMonthBegin(weekmask="Wed Thu")
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 12, 18),
...  freq=freq).strftime('%a%d %b %Y %H:%M')
Index(['Wed 03 Aug 2022 00:00', 'Thu 01 Sep 2022 00:00',
 'Wed 05 Oct 2022 00:00', 'Wed 02 Nov 2022 00:00',
 'Thu 01 Dec 2022 00:00'],
 dtype='object')

Using NumPy business day calendar you can define custom holidays.

>>> importdatetimeasdt
>>> bdc = np.busdaycalendar(holidays=['2022年08月01日', '2022年09月30日',
...  '2022年10月31日', '2022年11月01日'])
>>> freq = pd.offsets.CustomBusinessMonthBegin(calendar=bdc)
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 11, 10), freq=freq)
DatetimeIndex(['2022年08月02日', '2022年09月01日', '2022年10月03日', '2022年11月02日'],
 dtype='datetime64[ns]', freq='CBMS')

Attributes

base

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

cbday_roll

Define default roll function to be called in apply method.

freqstr

Return a string representing the frequency.

kwds

Return a dict of extra parameters for the offset.

month_roll

Define default roll function to be called in apply method.

n

name

Return a string representing the base frequency.

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(dt)

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

rollforward(dt)

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