I have financial time series for several countries and for each of those time series I want to drop observations that fall on public holidays of that particular country. To do that I'm creating a new column in my time series with boolean values to indicate if the date is a holiday or not.
So I found this code to assign boolean values and it works great for my US time series: Pandas: Checking if a date is a holiday and assigning boolean value
But I'm not able to get it to work for other countries. I tried using workalendar such as the code below but get error messages. I would appreciate any advice on using workalendar or other methods.
from datetime import date
from workalendar.europe import UnitedKingdom
cal = UnitedKingdom()
holidays = cal.holidays(start=uk_daily['Date for PH'].min(),
end=uk_daily['Date for PH'].max()).to_pydatetime()
uk_daily['Holiday'] = uk_daily['Date for PH'].isin(holidays)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-2d820caa4432> in <module>
4
5 holidays = cal.holidays(start=uk_daily['Date for PH'].min(),
----> 6 end=uk_daily['Date for PH'].max()).to_pydatetime()
TypeError: holidays() got an unexpected keyword argument 'start'
The data is just a Pandas dataframe with a time index and a few columns. I get the same error message using this reproducible example:
import pandas as pd
from datetime import date
from workalendar.europe import UnitedKingdom
cal = UnitedKingdom()
dr = pd.date_range(start='1996-01-01', end='2019-06-28')
df = pd.DataFrame()
df['Date'] = dr
holidays = cal.holidays(start=dr.min(), end=dr.max()).to_pydatetime()
df['Holiday'] = df['Date'].isin(holidays)
df.head(10)