class pandas.tseries.offsets.DateOffset(n=1, normalize=False, **kwds)
[source]
Standard kind of date increment used for a date range.
Works exactly like relativedelta in terms of the keyword args you pass in, use of the keyword n is discouraged– you would be better off specifying n in the keywords you use, but regardless it is there for you. n is needed for DateOffset subclasses.
DateOffset work as follows. Each offset specify a set of dates that conform to the DateOffset. For example, Bday defines this set to be the set of dates that are weekdays (M-F). To test if a date is in the set of a DateOffset dateOffset we can use the onOffset method: dateOffset.onOffset(date).
If a date is not on a valid date, the rollback and rollforward methods can be used to roll the date to the nearest valid date before/after the date.
DateOffsets can be created to move dates forward a given number of valid dates. For example, Bday(2) can be added to a date to move it two business days forward. If the date does not start on a valid date, first it is moved to a valid date. Thus pseudo code is:
When a date offset is created for a negative number of periods, the date is first rolled forward. The pseudo code is:
Zero presents a problem. Should it roll forward or back? We arbitrarily have it rollforward:
date + BDay(0) == BDay.rollforward(date)
Since 0 is a bit weird, we suggest avoiding its use.
Parameters: |
|
---|
See also
>>> ts = pd.Timestamp('2017-01-01 09:10:11') >>> ts + DateOffset(months=3) Timestamp('2017-04-01 09:10:11')
>>> ts = pd.Timestamp('2017-01-01 09:10:11') >>> ts + DateOffset(month=3) Timestamp('2017-03-01 09:10:11')
base | Returns a copy of the calling offset object with n=1 and all other attributes equal. |
freqstr | |
kwds | |
name | |
nanos | |
rule_code |
apply_index (self, other) | Vectorized apply of DateOffset to DatetimeIndex, raises NotImplentedError for offsets without a vectorized implementation. |
rollback (self, dt) | Roll provided date backward to next offset only if not on offset. |
rollforward (self, dt) | Roll provided date forward to next offset only if not on offset. |
__call__ | |
apply | |
copy | |
isAnchored | |
onOffset |
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.tseries.offsets.DateOffset.html