使用以下代码,我试图从 mongodb 中的对象中提取两个日期,然后计算两个日期之间的时间差——如果这两年都在 2016 年/过去。我当前的代码引发以下错误:
弃用警告:生成器 'QuerySet._iter_results' 从 ipykernel import kernelapp as app 引发了 StopIteration
我的代码: raw_data = Document.objects()
data = []
for i in raw_data[:10]:
scored = i.date_scored
scored_date = pd.to_datetime(scored, format='%Y-%m-%d %H:%M')
if scored_date == "NoneType":
print("none")
elif scored_date.year >= 2016:
extracted = i.date_extracted
extracted_date = pd.to_datetime(extracted, format='%Y-%m-%d
%H:%M')
bank = i.bank.name
diff = scored_date - extracted_date
print(diff)
datum = [str(bank), str(extracted), str(scored), str(diff)]
data.append(datum)
else:
pass
任何帮助将不胜感激,谢谢!