Pandas Date Offsets and Frequencies

August 1, 2022

from pandas.tseries.frequencies import to_offset
from pandas.tseries.offsets import DateOffset, MonthBegin, YearBegin, Week
 
 
p = pd.Timestamp('2021-08-25')
 
print(p - DateOffset(weeks=1))
print(p - Week(1))
print(p - to_offset('W'))
 
print()
 
print(p - DateOffset(months=1))
print(p - MonthBegin(1))
print(p - to_offset('1MS'))
 
print()
 
print(p - YearBegin(1))
 
print(isinstance(to_offset("MS"), MonthBegin))