Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas specifying custom holidays

I'm trying to specify business days in a foreign country, but I can't get the pandas function pd.bdate_range() to recognize holidays. My code is as follows:

import pandas as pd
import datetime

weekmask = "Mon Tue Wed Thu Fri"

holidays = [datetime.datetime(2017, 1, 9), datetime.datetime(2017, 3, 20),
            datetime.datetime(2017, 4, 13)]

BdaysCol2017 = pd.bdate_range(start = pd.datetime(2017, 1, 1), 
                              end = pd.datetime(2017, 12, 31), 
                              weekmask = weekmask, 
                              holidays = holidays)

But I get the following error on the holidays parameter:

ValueError: a custom frequency string is required when holidays or weekmask are passed, got frequency B

Why is this? How can I specify custom holidays? Is there a better way to do this?

Thank you

like image 452
scrps93 Avatar asked Mar 19 '19 19:03

scrps93


1 Answers

as the docs specify about weekmask and holidays:

only used when custom frequency strings are passed

so you need:

BdaysCol2017 = pd.bdate_range(start = pd.datetime(2017, 1, 1), 
                          end = pd.datetime(2017, 12, 31),
                          freq='C',
                          weekmask = weekmask,
                          holidays=holidays)
like image 117
Ezer K Avatar answered Nov 05 '22 09:11

Ezer K