Python Forum

Full Version: How to fill nan values with an expression
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'