The function below compares dates to filter a dataframe, but on line 8 it throws this error:
TypeError: Cannot compare type 'Timestamp' with type 'date'
It used to throw that same error on lines 5-7 , but when I addded the .date()
that fixed it, but the .date() does not fix it were I have it commented. Any clue why?
if day_of_week == 0: last_monday -= pd.to_timedelta(7, unit='d') last_sunday = last_monday + pd.to_timedelta(6, unit='d') last_sat = last_sunday - pd.to_timedelta(1, unit='d') finaldf['Completed_Date'] = pd.to_datetime(finaldf['Completed_Date'], format="%m/%d/%Y").dt.date finaldf['Due_Date'] = pd.to_datetime(finaldf['Due_Date'], format="%m/%d/%Y").dt.date last_week_flags = (finaldf.Completed_Date >= last_monday.date()) & (finaldf.Completed_Date <= last_sunday.date()) earlydue = (finaldf.Due_Date < last_monday.date()) # throws error here flags = last_week_flags & earlydue finaldf.loc[flags, 'Due_Date'] = last_monday finaldfmon = finaldf[last_week_flags] writer = pd.ExcelWriter('mondaysla.xlsx', engine='xlsxwriter') finaldfmon.to_excel(writer, index=False, sheet_name='Sheet1') earlydue = (finaldf.Due_Date < last_monday.date())