我必须在date列中添加'N‘no.of months,并尝试使用此函数来帮助我这样做。
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发布于 2021-02-04 14:54:42
在没有太多上下文的情况下,这是我用来捕获错误并提供备份编号的方法
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'您还可以在pandas apply函数中添加try except语句,这样就可以控制在出现IllegalMonthError异常时回填的值
https://stackoverflow.com/questions/43390013
复制相似问题