Python Forum
How to fill nan values with an expression
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fill nan values with an expression
#1
Hello guys, please make an effort trying to help me to know how to fill nan values with a certain expression.

If NaN value is True, I want to replace by the substrac of two dates to obtain the days between the dates.

Table:

Nan - 24/05/2017 - 25/05/2017
Nan - 24/06/2018 - 25/06/2018
35 - 10/03/2017 - 5/04/2017
I want to obtain

1 - 24/05/2017 - 25/05/2017
1 - 24/06/2018 - 25/06/2018
35 - 10/03/2017 - 5/04/2017
Please help.

Im trying to do with:

dfp['DIAS A ULTIMO SINIESTRO'] = dfp['DIAS A ULTIMO SINIESTRO'].fillna(value=np.where(dfp['ESTADO']==1,(dfp['FECHA_ANULACION']-dfp['FECHA_INI_VIGENCIA']).dt.days,(dfp['FECHA_FIN_VIGENCIA']-dfp['FECHA_INI_VIGENCIA']).dt.days))
But I obtain this error:

ValueError: invalid fill value with a class 'numpy.ndarray'
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020