0

我必须在日期列中添加“N”个月,并试图使用此功能来帮助我这样做。

order_emis_full['calc_due_date']=order_emis_full['agreement_date'].apply(lambda  x: x + relativedelta.relativedelta(months=1))  

我不断收到错误

 IllegalMonthError: bad month number nan; must be 1-12
4

1 回答 1

0

在没有太多上下文的情况下,我会这样做以捕获错误并提供备用号码

from calendar import IllegalMonthError

try:
   order_emis_full['calc_due_date']=order_emis_full['agreement_date'].apply(lambda  x: x + relativedelta.relativedelta(months=1))

except IllegalMonthError:
   'Your error catching code'

IllegalMonthError您还可以在 pandas 应用函数中添加 try except 语句,这样您就可以控制出现异常时要回填的值

于 2021-02-04T06:54:42.370 回答