Pandas TimeSeries MonthBegin and MonthEnd¶
import pandas as pd
from pandas.tseries.offsets import MonthBegin, MonthEnd
MonthEnd¶
Helpful when figuring out whether month ends on 28th, 29th, 30th, 31st.
todays_date = '2021-02-07'
month_end_date = pd.to_datetime(todays_date) + MonthEnd(1)
print(month_end_date)
MonthBegin¶
Helpful when figuring out when current/previous/next MonthBegin.
month_start_date = pd.to_datetime(todays_date) + MonthBegin(-1)
print(month_start_date)
next_month_start_date = pd.to_datetime(todays_date) + MonthBegin(1)
print(next_month_start_date)