Calendar.filter#
- Calendar.filter(func=None, *, year: int = None, semester: int = None, quarter: int = None, month: int = None, week: int = None, weekday: str = None)#
Filters and returns a new calendar from this calendar based on a criteria.
Allowed criteria are: - either a filtering function (lambda) - one or several filtering frequencies as named arguments
- Parameters:
func (function, optional) – a filtering function (receives each date as argument)
year (int, optional) – pass a value to filter dates of the given year only
semester (int, optional (1 or 2)) – pass a value to filter dates of the given semester only
quarter (int, optional (1, 2, 3, or 4)) – pass a value to filter dates of the given quarter only
month (int, optional (1 through 12)) – pass a value to filter dates of the given month only
week (int, optional (1 through 53)) – pass a value to filter dates of the given week number only
weekday (int, optional (0 through 6)) – pass a value to filter dates of the given weekday only Monday = 0, Tuesday = 1… Sunday = 6
- Return type:
Example
Filter dates from 3Q 2020 >>> calendar = Calendar(dates) #assume dates is a list of dates >>> calendar.filter(year=2020, quarter=3)
Filter Mondays >>> calendar = Calendar(dates) >>> calendar.filter(lambda date: date.weekday() == 0)