In Pandas, I know you can use anchor offsets to specify more complicated reucrrences: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#anchored-offset
I want to specify a date_range such that it is monthly on the nth day of each month. What is the best syntax to do that with? I'm imaginging something similar to this which specifies a recurrence every 2 weeks on Friday:
schedule = pd.date_range(start=START_STR, periods=26, freq="2W-FRI")
No need to re-invent the wheel. Use DateOffset
from pandas:
import pandas as pd
from pandas.tseries.offsets import DateOffset
from datetime import date
date1 = date(2019,1,29)
pd.date_range(date1, periods=12, freq=DateOffset(months=1))
Output:
DatetimeIndex(['2019-01-29', '2019-02-28', '2019-03-28', '2019-04-28',
'2019-05-28', '2019-06-28', '2019-07-28', '2019-08-28',
'2019-09-28', '2019-10-28', '2019-11-28', '2019-12-28'],
dtype='datetime64[ns]', freq='<DateOffset: months=1>')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With