title: Modifying a subset of rows in a pandas dataframe
body: <p>Assume I have a pandas DataFrame with two columns, A and B. I'd like to modify this DataFrame (or create a copy) so that B is always NaN whenever A is 0. How would I achieve that?</p>
  
  <p>I tried the following</p>
  
  <pre><code>df['A'==0]['B'] = np.nan
  </code></pre>
  
  <p>and</p>
  
  <pre><code>df['A'==0]['B'].values.fill(np.nan)
  </code></pre>
  
  <p>without success.</p>