I have a pandas dataframe object df
for the following dates:
>> df.index
DatetimeIndex(['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04',
'2015-01-05', '2015-01-06', '2015-01-07', '2015-01-08',
'2015-01-09', '2015-01-10'],
dtype='datetime64[ns]', name='Date', length=10, freq=None)
I want to add a column to df
showing whether or not it is a public holiday:
import pandas as pd
import holidays
df['hols'] = holidays.CountryHoliday('AUS',prov='NSW').get(df.index.to_datetime())
and get the error: AttributeError: 'DatetimeIndex' object has no attribute 'to_datetime'
.
If I try
df['hols'] = holidays.CountryHoliday('AUS',prov='NSW').get(pd.to_datetime(df.index))
I get error TypeError: Cannot convert type '<class 'pandas.core.indexes.datetimes.DatetimeIndex'>' to date.
I'm aware of the workalendar
package from Adding holidays columns in a Dataframe in Python, but I can't install the package on my university PC.