champpy.TypeDays¶
- class champpy.TypeDays(groups=[[0], [1], [2], [3], [4], [5], [6]])[source]¶
Utility class to group weekdays into typedays.
The class allows to define custom groups of weekdays (e.g., Mon-Fri, Sat-Sun) and provides methods to convert weekday indices to typeday indices.
- Parameters:
groups (
list[list[int]]) – List of weekday groups. Each inner list defines one typeday and contains weekday indices (0=Monday…6=Sunday).
- names¶
The names of each typeday based on the grouped weekdays (e.g., “Mon-Fri”, “Sat-Sun”).
Examples
>>> typedays = TypeDays(groups=[[0, 1, 2, 3, 4], [5, 6]]) >>> typedays.index [0, 1] >>> typedays.names ['Mon-Fri', 'Sat-Sun']
>>> TypeDays(groups=[[0, 1, 2, 3, 4], [5], [6]]).names ['Mon-Fri', 'Sat', 'Sun']
>>> TypeDays(groups=[[0, 2, 4], [1, 3, 5, 6]]).names ['Mon-Fri', 'Tue-Sun']
- weekday2typeday(index_weekday)[source]¶
Convert weekday (0=Monday,..6=Sunday) to typeday index based on groups.
- Parameters:
index_weekday (
int|Series|ndarray) – Weekday index or array/series of weekday indices.- Return type:
Examples
>>> typedays = TypeDays(groups=[[0, 1, 2, 3, 4], [5, 6]]) >>> typedays.weekday2typeday(np.array([0, 1, 2, 3, 4, 5, 6, 4, 6])) [0, 0, 0, 0, 0, 1, 1, 0, 1]