Filling nulls with a list in Pandas using fillna
Use apply
, because fillna
working with scalars only:
print (ser.apply(lambda x: [np.nan] if pd.isnull(x) else x))0 01 12 [nan]dtype: object
You can change to object
ser=ser.astype('object')
Then assign the list np.nan
ser.loc[ser.isnull()]=[[np.nan]]
I ended up using
ser.loc[ser.isnull()] = ser.loc[ser.isnull()].apply(lambda x: [np.nan])
because pd.isnull(x) would give me ambiguous truth values error ( i have other lists in my series too ). This is a combination of YOBEN_S' and jezrael's answer.