Skip to content Skip to sidebar Skip to footer

Moving Backwards In Time Until Specific Dates With A Given Frequency (month) In Python

I would like to have a list of date every year from an end date spaced in given month amount. For example if my end is '20251220' and I have a paramter freq which steers the time s

Solution 1:

You can do it with date_range, setting end date as now and frequency in DateOffset:

pd.date_range('20250220', 'now', freq=-pd.DateOffset(months=12//freq))[1:]

Output:

DatetimeIndex(['2024-02-20', '2023-02-20', '2022-02-20'], dtype='datetime64[ns]', freq='<-1 * DateOffset: months=12>')

Post a Comment for "Moving Backwards In Time Until Specific Dates With A Given Frequency (month) In Python"