title: Pandas replace values in dataframe conditionally based on string compare
body: <p>I have a pandas dataframe as below with 3 columns. I want to compare each column to see if the value matches a particular string, and if yes, replace the value with NaN.</p>
  
  <p>For example, if there are 5 values in column 1 of the data frame: </p>
  
  <pre><code>abcd
  abcd
  defg
  abcd
  defg
  </code></pre>
  
  <p>and if the comparison string is <code>defg</code>, the end result for column 1 in the data frame should be.</p>
  
  <pre><code>abcd
  abcd
  NaN
  abcd
  NaN
  </code></pre>