📌  相关文章
📜  Python| Pandas tseries.offsets.CustomBusinessDay.name(1)

📅  最后修改于: 2023-12-03 15:19:16.330000             🧑  作者: Mango

Python | Pandas tseries.offsets.CustomBusinessDay.name

Pandas is a powerful library for data manipulation and analysis. Tseries module in Pandas provides time series functionality for various frequencies. In this article, we will discuss tseries.offsets.CustomBusinessDay.name from the offset module.

Syntax:

pandas.tseries.offsets.CustomBusinessDay(name=None, weekmask='Mon Tue Wed Thu Fri', holidays=None, calendar=None, normalize=False, offset=None)

The CustomBusinessDay offset returns a set of business days of custom frequency. It is a subclass of pd.tseries.offsets.CustomBusinessDay. The name parameter is used to refer to this custom business day object.

Parameters:

  • name : object (optional) A custom name to be assigned to the date offset.
  • weekmask : str or None (default ‘Mon Tue Wed Thu Fri’) The weekdays which should be considered as valid days. Only these days will be included in the set of valid business days. For example:
    • 'Mon Tue Wed Thu Fri'
    • 'Sat Sun'.
  • holidays : array-like or None (default None) A list of dates to be considered as holidays. Any holidays that fall on a valid business day will be included in the set of valid business days.
  • calendar : pandas.tseries.holiday.Calendar or subclass or None (default None) Parent holidays calendar.
  • normalize : bool (default False) Return the result as an all days (24/7) offset, anchored to midnight.
  • offset : Timedelta or str or None An additional time delta to apply to each business day.

Return type: pandas.tseries.offsets.CustomBusinessDay

Example
import pandas as pd
from datetime import datetime
from pandas.tseries.offsets import CustomBusinessDay

# Custom business day starting from April 15, 2021
my_custom_business_day = CustomBusinessDay(name='my_custom_business_day', weekmask='Mon Tue Wed Thu Fri', holidays=[pd.to_datetime('2021-05-01')])

start_date = pd.to_datetime('2021-04-15')

# Add 5 custom business days to start date
end_date = start_date + 5*my_custom_business_day

print(end_date)

Output:

Timestamp('2021-04-22 00:00:00')

In the above code, we have defined a CustomBusinessDay called "my_custom_business_day" which includes weekdays Monday to Friday and excludes the holiday "2021-05-01". We then added 5 my_custom_business_day's to the start date "2021-04-15" to get "2021-04-22".

Conclusion

In this article, we have discussed tseries.offsets.CustomBusinessDay.name from the offset module. CustomBusinessDay is useful when we want to deal with custom frequency business days. We can define weekdays, holidays, and a name for the CustomBusinessDay object.