python numpy array replace nan with string

Solutions on MaxInterview for python numpy array replace nan with string by the best coders in the world

showing results for - "python numpy array replace nan with string"
Lucien
13 May 2020
1import numpy as np
2l=['foo', 'bar', 'baz', np.nan]
3
4l_new=['missing' if x is np.nan else x for x in l]
5
6print l_new
7# Result:
8# ['foo', 'bar', 'baz', 'missing']