title: Replace Numpy NaN with string in list with strings
body: <p>I have a list containing string elements, and several NaN numpy floats. E.g.</p>
  
  <pre><code>l=['foo', 'bar', 'baz', 'nan']
  </code></pre>
  
  <p>How do I replace the float <code>nan</code> to the string <code>missing</code>? </p>
  
  <p>Most answers I found regard this issue in a pandas DataFrame.
  <hr>
  <strong>Try 1:</strong> </p>
  
  <pre><code>for x in l:
      x=x.replace('nan', 'missing')
  </code></pre>
  
  <p>gives <code>AttributeError: 'float' object has no attribute 'replace'</code></p>
  
  <p><strong>Try 2:</strong> </p>
  
  <pre><code>for x in l:
     if str(x)=='nan':
         x=str(x)
  </code></pre>
  
  <p>Command executes, but nothing changes.
  <hr>
  <strong>Advised by comments:</strong> </p>
  
  <ol>
  <li><code>['missing' if x is 'nan' else x for x in l]</code></li>
  <li><code>['missing' if x is np.isnan else x for x in l]</code></li>
  <li><code>['missing' if x is np.nan else x for x in l]</code></li>
  </ol>
  
  <p>Commands execute, but nothing changes.</p>