replace() method not working on Pandas DataFrame
<p>I have looked up this issue and most questions are for more complex replacements. However in my case I have a very simple dataframe as a test dummy.</p>
<p>The aim is to replace a string anywhere in the dataframe with an nan, however this does not seem to work (i.e. does not replace; no errors whatsoever). I've tried replacing with another string and it does not work either. E.g.</p>
<pre><code>d = {'color' : pd.Series(['white', 'blue', 'orange']),
   'second_color': pd.Series(['white', 'black', 'blue']),
   'value' : pd.Series([1., 2., 3.])}
df = pd.DataFrame(d)
df.replace('white', np.nan)
</code></pre>
<p>The output is still:</p>
<pre><code>      color second_color  value
  0   white        white      1
  1    blue        black      2
  2  orange         blue      3
</code></pre>
<hr />
<p><sub>This problem is often addressed using <code>inplace=True</code>, but there are caveats to that. Please also see <a href="https://stackoverflow.com/questions/43893457">Understanding inplace=True in pandas</a>.</sub></p>