I have a spreadsheet that lists vacation days for different schools. An example is:
Labor Day Fall Break Veterans Day Random Holiday
DistrictA 9/2 10/14 11/11
DistrictB 9/2 10/13-10/14 11/11 12/17,12/19
The holidays are either single dates, ranges (separated by hyphen), or multiple dates (separated by commas).
I am trying to create an array where given a District name and a date, it will simply return if this is a holiday or not (True/False).
The basics of what I have are:
import pandas as pd
vacation = pd.read_excel("Vacations.xlsx")
v = {}
for index, row in vacation.iterrows():
v[row[0]] = row.values.tolist()[1:]
print(v)
This creates a dictionary where the key is the District name and the values are an array of the time range values (datetime
object, Timestamp
object, string (if date is range or multiple), nan (Not a #), or NaT (not a time)
One idea I had is to go through each date value and append the dates to a new list. So for example:
'DistrictA': [datetime.datetime(2019,9,2), '10/13-10/15', Timestamp('2019-11-11 00:00:00')]
would turn into
'DistrictA': [datetime.datetime(2019,9,2), datetime.datetime(2019,10,13), datetime.datetime(2019,10,14), datetime.datetime(2019,10,15), datetime.datetime(2019,11,11)]
But I am sure there is a much better way. What is the best way to check if a given date is a holiday?