pandas.tseries.offsets.CustomBusinessMonthEnd#

class pandas.tseries.offsets.CustomBusinessMonthEnd(n=1, normalize=False, weekmask='Mon Tue Wed Thu Fri', holidays=None, calendar=None, offset=datetime.timedelta(0))#

DateOffset subclass representing custom business month(s).

Increments between end of month dates.

Parameters:
nint, default 1

The number of months represented.

normalizebool, default False

Normalize end 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.

Attributes

m_offset

Return a MonthBegin or MonthEnd offset.

weekmask

Return the weekmask used for custom business day calculations.

holidays

Return the holidays used for custom business day calculations.

calendar

Return the calendar used for business day calculations.

offset

Return the time offset applied to the business day.

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.CustomBusinessMonthEnd()
Timestamp('2022-08-31 00:00:00')

Custom business month end 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.

>>> import datetime as dt
>>> freq = pd.offsets.CustomBusinessMonthEnd(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(['Thu 28 Jul 2022 00:00', 'Wed 31 Aug 2022 00:00',
       'Thu 29 Sep 2022 00:00', 'Thu 27 Oct 2022 00:00',
       'Wed 30 Nov 2022 00:00'],
       dtype='str')

Using NumPy business day calendar you can define custom holidays.

>>> import datetime as dt
>>> bdc = np.busdaycalendar(holidays=['2022-08-01', '2022-09-30',
...                                   '2022-10-31', '2022-11-01'])
>>> freq = pd.offsets.CustomBusinessMonthEnd(calendar=bdc)
>>> pd.date_range(dt.datetime(2022, 7, 10), dt.datetime(2022, 11, 10), freq=freq)
DatetimeIndex(['2022-07-29', '2022-08-31', '2022-09-29', '2022-10-28'],
               dtype='datetime64[us]', freq='CBME')