cmp
cmp

Reputation: 568

Pandas `bdate_range' returns list of dates that include weekends

I am using Pandas version 1.2.3 to generate a list of business days within a business quarter, 'BQ'.

Unfortunately, the following implementation seems to generate dates that include weekends:

import pandas as pd
import datetime

dates = pd.bdate_range(
    start=datetime.date(2015, 1, 1), 
    end=datetime.date(2019, 1, 1),
    freq='BQ'
    )

With the above implementation, one of the dates within the defined bounds above is '2017-12-31', which is a Sunday?

My inputs appear to be consistent with what the function signature expects as per the documentation https://pandas.pydata.org/docs/reference/api/pandas.bdate_range.html.

Am I doing something incorrect here?

Thank you.

Upvotes: 0

Views: 843

Answers (1)

ragas
ragas

Reputation: 916

With the following code, I'm not getting 2017-12-31

import pandas as pd
import datetime

dates = pd.bdate_range(
    start=datetime.date(2015, 1, 1), 
    end=datetime.date(2019, 1, 1)
    )

Another option:

    from pandas.tseries.offsets import CustomBusinessDay
    from pandas.tseries.holiday import USFederalHolidayCalendar

    us_bd = CustomBusinessDay(calendar=USFederalHolidayCalendar())
    dates = pd.date_range(start=datetime.date(2015, 1, 1),end=datetime.date(2019, 1, 1), freq=us_bd)

Upvotes: 0

Related Questions