Assume you have two pandas datetimes: from_date and end_date. I need a function that splits it into folds of n months (lets say n=3). For example:
import pandas as pd
from_date = pd.to_datetime("2020-02-15")
to_date = pd.to_datetime("2020-05-20")
should be splitted into 2 folds:
{
"1": {"from_date": 2020-02-15, "to_date": 2020-05-15},
"2": {"from_date": 2020-05-16, "to_date": 2020-05-20}
}
each fold needs to satisfy the condition:
from_date + pd.DateOffset(months=2) >= end_date. So it is not about the number of days between start and end date.
what is the most pythonic way to do this? Is there something in pandas?