我需要根据某些规则来计算两个日期之间的天数。
我有以下代码可以工作,但是最后一个“ elif”不起作用,因为我似乎无法执行“ is not NaT” ...
def life(x):
active = x.Active
mind = x.MinDate
close = x.CloseDate
today = pd.to_datetime(date.today())
if active == 1:
return (today2 - mind)
elif active == 0 and close:
return (close - mind)
elif active == 0 and not close:
return datetime.timedelta(days=0)
else:
return 'CHECK'
我也尝试过'close == None',但是我仍然不会在输出中得到'0 days'。