Given some reference date, trying to find the next Jan, May, Sep, e.g. the next relevant date after 2016-02 should be 2016-05.
Current way that working for me (not pythonic) looks like:
def rel_month(dt):
rel_mon = [1, 5, 9]
ref_dt = pd.Timestamp(dt)
idx = pd.DatetimeIndex(start=ref_dt, end=ref_dt + pd.Timedelta('122D'), freq='M')
return idx[idx.month.isin(rel_mon)][0].strftime('%Y-%m')
In most case we can use for loop to solve ANY problem. But we are trying to avoid for loops here, hence the title "pythonic". Without for loops, weekday is definitely different from month.