doubledate.dayof#
- doubledate.dayof(frequency: str, dates=None, *, calendar=None, base=1)#
Returns an efficient iterator that yields the position of each date in a given frequency.
- Parameters:
dates (datetime, iterable) – either a date or an iterable of dates
frequency (str) – one of Y, H, T, Q, M, W, W-MON,W-TUE,W-WED,W-THU,W-FRI,W-SAT,W-SUN
calendar (iterable) – custom calendar to use
base (int, defaults to 1) – whether the first date of the frequency should have value 0 or 1
- Returns:
mapping – dictionary-like container mapping dates to position in frequency
- Return type:
Examples
>>> dayof(datetime.date(2020,2,29), "M") 29 >>> dayof(datetime.date(2020,2,29), "Q") 60 >>> dayof(datetime.date(2020,2,29), "W-THU") #Saturday 3 >>> dates = [datetime.date(2020,1,1) + datetime.timedelta(i) for i in range(90) if i % 12 != 0] >>> for date, position in zip(dates, dayof("M", calendar=dates)): ... print(date, position) 2020-01-02, 1 2020-01-03, 2 ... 2020-02-29,27 2020-03-02,1 ... 2020-03-30,27 >>> dayof("Q", calendar=dates)[datetime.date(2020,3,30)] 81
Notes
Warning
If given a calendar and no dates, the function returns a date-map, mapping each date of the custom calendar to its position within the frequency.
If given a set of dates and no calendar, the function returns the number of days from the generic start of the frequency.
If given a set of dates and a custom calendar, the function returns the number of days since the start of the frequency using the custom calendar as the reference.