I have a pandas dataframe, it has a column with date (datetime) and a column with day of the week (Mon-Sun). I would like to create a new column that would show whether it's a weekday, weekend or a holiday. Including a snapshot of dataframe for reference.
This is the function I wrote, I'm listing the holidays one by one since there are only 6.
def day_type (day_month, day_week):
if (day_month == '2013-01-01' or day_month == '2013-05-27' or day_month == '2013-07-04' \
or day_month == '2013-09-02' or day_month == '2013-11-28' or day_month == '2013-12-25'):
return "H"
elif day_week == "Saturday" or day_week =="Sunday":
return "WE"
else:
return "WD"
I am then executing the function with apply where LoadData['Date'] is my day_month and LoadData['DoW'] is my day_week.
LoadData["DayType"] = LoadData[['Date','DoW']].apply(day_type)
I get the following error:
TypeError: day_type() missing 1 required positional argument: 'day_week'
I have tried using lambda as well to apply the function but I got an error as well:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I must be missing something; I've tried this in many different ways and still not getting anywhere.