Date Offset Classes#
DateOffset classes represent regular frequency offsets for date arithmetic.
DateOffset#
Base class for date offsets.
import pandasCore as pd
# Create offset
offset = pd.DateOffset(days=1)
# Add to timestamp
ts = pd.Timestamp('2023-01-01')
ts + offset # 2023-01-02
Parameters#
Parameter |
Type |
Default |
Description |
|---|---|---|---|
n |
int |
1 |
Number of periods |
normalize |
bool |
False |
Normalize to midnight |
years |
int |
0 |
Years to add |
months |
int |
0 |
Months to add |
weeks |
int |
0 |
Weeks to add |
days |
int |
0 |
Days to add |
hours |
int |
0 |
Hours to add |
minutes |
int |
0 |
Minutes to add |
seconds |
int |
0 |
Seconds to add |
Time Offsets#
Class |
Alias |
Description |
|---|---|---|
Day |
D |
One day |
Hour |
H |
One hour |
Minute |
T, min |
One minute |
Second |
S |
One second |
Milli |
L, ms |
One millisecond |
Micro |
U, us |
One microsecond |
Nano |
N, ns |
One nanosecond |
Month Offsets#
Class |
Alias |
Description |
|---|---|---|
MonthEnd |
M |
End of month |
MonthBegin |
MS |
Start of month |
BusinessMonthEnd |
BM |
Business month end |
BusinessMonthBegin |
BMS |
Business month start |
Quarter Offsets#
Class |
Alias |
Description |
|---|---|---|
QuarterEnd |
Q |
End of quarter |
QuarterBegin |
QS |
Start of quarter |
BQuarterEnd |
BQ |
Business quarter end |
BQuarterBegin |
BQS |
Business quarter start |
Year Offsets#
Class |
Alias |
Description |
|---|---|---|
YearEnd |
A, Y |
End of year |
YearBegin |
AS, YS |
Start of year |
BYearEnd |
BA, BY |
Business year end |
BYearBegin |
BAS, BYS |
Business year start |
Business Day Offsets#
Class |
Alias |
Description |
|---|---|---|
BusinessDay |
B |
Business day |
BusinessHour |
BH |
Business hour |
CustomBusinessDay |
C |
Custom business day |
Common Methods#
All offset classes support:
Method |
Description |
|---|---|
apply(ts) |
Apply offset to timestamp |
rollback(ts) |
Roll back to previous period boundary |
rollforward(ts) |
Roll forward to next period boundary |
is_on_offset(ts) |
Check if timestamp is on offset |
copy() |
Create copy of offset |