make_weekday_sequence

make_weekday_sequence(start_date, end_date, sunday_to_thursday=False, remove_holidays=False, country=None, engine='pandas')

Generate a sequence of weekday dates within a specified date range, optionally excluding weekends and holidays.

Parameters

Name Type Description Default
start_date str or datetime or pd.DatetimeIndex The start date of the date range. required
end_date str or datetime or pd.DatetimeIndex The end date of the date range. required
sunday_to_thursday bool If True, generates a sequence with Sunday to Thursday weekdays (excluding Friday and Saturday). If False (default), generates a sequence with Monday to Friday weekdays. False
remove_holidays (bool, optional) If True, excludes holidays (based on the specified country) from the generated sequence. If False (default), includes holidays in the sequence. False
country str The name of the country for which to generate holiday-specific sequences. Defaults to None, which uses the United States as the default country. None
engine str The engine parameter is used to specify the engine to use for generating a weekday series. It can be either “pandas” or “polars”. - The default value is “pandas”. - When “polars”, the function will internally use the polars library for generating a weekday series. This can be faster than using “pandas” for large datasets. 'pandas'

Returns

Type Description
pd.Series A Series containing the generated weekday dates.

Examples

import pandas as pd
import pytimetk as tk

# United States has Monday to Friday as weekdays (excluding Saturday and 
# Sunday and holidays)
tk.make_weekday_sequence("2023-01-01", "2023-01-15", 
                          sunday_to_thursday = False, 
                          remove_holidays    = True, 
                          country            = 'UnitedStates',
                          engine             = 'pandas')
0   2023-01-03
1   2023-01-04
2   2023-01-05
3   2023-01-06
4   2023-01-09
5   2023-01-10
6   2023-01-11
7   2023-01-12
8   2023-01-13
Name: Weekday Dates, dtype: datetime64[ns]
# Israel has Sunday to Thursday as weekdays (excluding Friday and Saturday 
# and Israel holidays)
tk.make_weekday_sequence("2023-01-01", "2023-01-15", 
                          sunday_to_thursday = True, 
                          remove_holidays    = True, 
                          country            = 'Israel',
                          engine             = 'pandas')
0    2023-01-01
1    2023-01-02
2    2023-01-03
3    2023-01-04
4    2023-01-05
5    2023-01-08
6    2023-01-09
7    2023-01-10
8    2023-01-11
9    2023-01-12
10   2023-01-15
Name: Weekday Dates, dtype: datetime64[ns]
# Israel has Sunday to Thursday as weekdays (excluding Friday and Saturday 
# and Israel holidays)
tk.make_weekday_sequence("2023-01-01", "2023-01-15", 
                          sunday_to_thursday = True, 
                          remove_holidays    = True, 
                          country            = 'Israel',
                          engine             = 'polars')
0   2023-01-02
1   2023-01-03
2   2023-01-04
3   2023-01-05
4   2023-01-09
5   2023-01-10
6   2023-01-11
7   2023-01-12
Name: Weekday Dates, dtype: datetime64[ns]