Python Forum
How to fill nan values with an expression - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: How to fill nan values with an expression (/thread-11236.html)



How to fill nan values with an expression - Jaarroy - Jun-29-2018

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'