I'm trying to create a "workday" column that flags a range of dates as either "True" or "False" based on if it is a weekday and if it is a holiday. If it's a weekday and also not a holiday, then it is considered a "workday," else not a workday.
everything seems to be going as intended until the the last line. I've created the new column named "workday," filled the values as whatever is in "weekday," but then when I go to replace the values in "workday" as false where "holiday" is True, it doesn't seem to be doing anything.
Where am I going wrong here? Also, let me know if you have any thoughts on simplifying my code, I'm clearly a beginner. :) Any help is appreciated!
import pandas as pd
import numpy as np
from datetime import datetime
from pandas.tseries.holiday import USFederalHolidayCalendar as holidaylist
datelist = pd.date_range(start='2018-08-01', end=datetime.today())
bizdaylist = pd.date_range(start='2018-08-01', end=datetime.today(), freq='B')
df1_columns = ['date']
df1 = pd.DataFrame(datelist, columns = df1_columns)
df2_columns = ['date']
df2 = pd.DataFrame(bizdaylist, columns = df2_columns)
df1 = df1.assign(weekday=df1.date.isin(df2.date).astype(str))
df3 = pd.DataFrame()
df3['Date'] = datelist
hl = holidaylist()
holidays = hl.holidays(start=datelist.min(), end=datelist.max())
df1['holiday'] = df3['Date'].isin(holidays)
df1['workday'] = np.where(df1.holiday == 'FALSE', df1.holiday, df1.weekday)
print(df1.loc[877:884])
dataframe index 877-884: