Python 无法比较日期变量和数据框之间的日期

Python 无法比较日期变量和数据框之间的日期,python,excel,pandas,date,formatting,Python,Excel,Pandas,Date,Formatting,在比较变量日期和日期数据集时,我遇到了一个令人沮丧的问题。无论我尝试什么格式选项,我都无法使它们一致。 请大家帮忙,我基本上只需要将熊猫数据集中的日期与今天的日期+6个月进行比较 我的代码: SourceData_Workbook = R"G:\AR\REPORTS\Automation Files\Credit Risk\test1.xlsx" SourceInPandas = pd.read_excel(SourceData_Workbook, skiprows=33,

在比较变量日期和日期数据集时,我遇到了一个令人沮丧的问题。无论我尝试什么格式选项,我都无法使它们一致。 请大家帮忙,我基本上只需要将熊猫数据集中的日期与今天的日期+6个月进行比较

我的代码:

SourceData_Workbook = R"G:\AR\REPORTS\Automation Files\Credit Risk\test1.xlsx"

SourceInPandas = pd.read_excel(SourceData_Workbook, skiprows=33,header=0,index=False)

# Creating date variable + 6 months
six_months = date.today() + relativedelta(months=+6)


# Formatting sourced data to date format
SourceInPandas['Req.dlv.dt']=SourceInPandas['Req.dlv.dt'].apply(lambda x:datetime.strptime(x,'%d.%m.%Y'))

# Fails on this line
SourceInPandas.loc[(SourceInPandas['Req.dlv.dt']<= six_months) & (SourceInPandas['OpIt'] != "15 Overdue account")& (SourceInPandas['OpIt'] != "16 Prepayment required")& (SourceInPandas['OpIt'] != "17 Approval required"),"OpIt"]="Future delivery" 
您可以通过以下方式使用并添加6个月:


不幸的是,即使这样也会打印出同样的错误:dtype=datetime64[ns]和dateDiky uz到hrne之间的比较无效!Zdravim SK z Brna.)
TypeError: Invalid comparison between dtype=datetime64[ns] and date 
six_months = pd.Timestamp('today').floor('d') + pd.DateOffset(months=6)
print (six_months)
2021-06-10 00:00:00

SourceInPandas['Req.dlv.dt']=pd.to_datetime(SourceInPandas['Req.dlv.dt'], dayfirst=True)