Pandas - TypeError: Cannot compare type 'Timestamp' with type 'date'

匿名 (未验证) 提交于 2019-12-03 01:46:01

问题:

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()) 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!