Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python numpy array replace nan with string

import numpy as np
l=['foo', 'bar', 'baz', np.nan]

l_new=['missing' if x is np.nan else x for x in l]

print l_new
# Result:
# ['foo', 'bar', 'baz', 'missing']
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #numpy #array #replace #nan #string
ADD COMMENT
Topic
Name
8+4 =