title: Pandas: Conditionally replace values based on other columns values
body: <p>I have a dataframe (df) that looks like this:</p>
  
  <pre><code>                    environment     event   
  time                    
  2017-04-28 13:08:22     NaN         add_rd  
  2017-04-28 08:58:40     NaN         add_rd  
  2017-05-03 07:59:35     test        add_env
  2017-05-03 08:05:14     prod        add_env
  ...
  </code></pre>
  
  <p>Now my goal is for each <code>add_rd</code> in the <code>event</code> column, the associated <code>NaN</code>-value in the <code>environment</code> column should be replaced with a string <code>RD</code>.</p>
  
  <pre><code>                    environment     event   
  time                    
  2017-04-28 13:08:22     RD          add_rd  
  2017-04-28 08:58:40     RD          add_rd  
  2017-05-03 07:59:35     test        add_env
  2017-05-03 08:05:14     prod        add_env
  ...
  </code></pre>
  
  <hr>
  
  <p><strong>What I did so far</strong></p>
  
  <p>I stumbled across <code>df['environment'] = df['environment].fillna('RD')</code> which replaces <strong>every</strong> <code>NaN</code> (which is not what I am looking for), <code>pd.isnull(df['environment'])</code> which is detecting missing values and <code>np.where(df['environment'], x,y)</code> which seems to be what I want but isn't working. <strong>Furthermore did I try this</strong>:</p>
  
  <pre><code>import pandas as pd
  
  for env in df['environment']:
      if pd.isnull(env) and df['event'] == 'add_rd':
          env = 'RD'
  </code></pre>
  
  <p>The indexes are missing or some kind of iterator to access the equivalent value in the <code>event</code> column.<br>
  <strong>And I tried this</strong>:</p>
  
  <pre><code>df['environment'] = np.where(pd.isnull(df['environment']), df['environment'] = 'RD', df['environment'])
  
  SyntaxError: keyword can't be an expression
  </code></pre>
  
  <p>which obviously didn't worked. </p>
  
  <p>I took a look at several questions but couldn't build on the suggestions in the answers. <a href="https://stackoverflow.com/a/23307361/10099689">Black's question</a> <a href="https://stackoverflow.com/a/31888920/10099689">Simon's question</a> <a href="https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas">szli's question</a> <a href="https://stackoverflow.com/a/10726275/10099689">Jan Willems Tulp's question</a></p>
  
  <p>So, how do I replace a value in a column based on another columns values?</p>