polars_xdt.workday_count#
- polars_xdt.workday_count(start_dates: IntoExpr, end_dates: IntoExpr, weekend: Sequence[str] = ('Sat', 'Sun'), holidays: Sequence[date] | None = None) pl.Expr #
Count the number of workdays between two columns of dates.
- Parameters:
- start_dates
Start date(s). This can be a string column, a date column, or a single date.
- end_dates
End date(s). This can be a string column, a date column, or a single date.
- weekend
The days of the week that are considered weekends. Defaults to (“Sat”, “Sun”).
- holidays
The holidays to exclude from the calculation. Defaults to None. This should be a list of
datetime.date
s.
- Returns:
- polars.Expr
Examples
>>> from datetime import date >>> import polars as pl >>> import polars_xdt as xdt >>> df = pl.DataFrame( ... { ... "start": [date(2023, 1, 4), date(2023, 5, 1), date(2023, 9, 9)], ... "end": [date(2023, 2, 8), date(2023, 5, 2), date(2023, 12, 30)], ... } ... ) >>> df.with_columns(n_business_days=xdt.workday_count("start", "end")) shape: (3, 3) ┌────────────┬────────────┬─────────────────┐ │ start ┆ end ┆ n_business_days │ │ --- ┆ --- ┆ --- │ │ date ┆ date ┆ i32 │ ╞════════════╪════════════╪═════════════════╡ │ 2023-01-04 ┆ 2023-02-08 ┆ 25 │ │ 2023-05-01 ┆ 2023-05-02 ┆ 1 │ │ 2023-09-09 ┆ 2023-12-30 ┆ 80 │ └────────────┴────────────┴─────────────────┘