Nan fill-list values
3 answers
You can use a list comprehension and check with math.isnan :
import math
listname = [0 if math.isnan(x) else x for x in listname]
But that won't work with non float types, if your list has strings, other numeric types, etc., then you can use str(x) != 'nan
'
listname = [0 if str(x)=='nan' else x for x in listname]
0
source to share