How to fill nan values with 0's in a list. I can do it for dataframes but don't know how to do it for lists?
listname=listname.fillna(0)
This isn't working.
You can convert to a pandas series and back to a list
pd.Series(listname).fillna(0).tolist()
Consider the list listname
listname = [1, np.nan, 2, None, 3]
Then
pd.Series(listname, dtype=object).fillna(0).tolist()
[1, 0, 2, 0, 3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With