title: Copy and Paste Values Based on a Condition in Python
body: <p>I am trying to populate column 'C' with values from column 'A' based on conditions in column 'B'.  Example: If column 'B' equals 'nan', then row under column 'C' equals the row in column 'A'. If column 'B' does NOT equal 'nan', then leave column 'C' as is (ie 'nan'). Next, the values in column 'A' to be removed (only the values that were copied from column A to C).</p>
  
  <p>Original Dataset:</p>
  
  <pre><code>index   A   B    C
  0       6   nan  nan
  1       6   nan  nan
  2       9   3    nan
  3       9   3    nan
  4       2   8    nan
  5       2   8    nan
  6       3   4    nan
  7       3   nan  nan
  8       4   nan  nan
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>index   A   B    C
  0       nan nan  6
  1       nan nan  6
  2       9   3    nan
  3       9   3    nan
  4       2   8    nan
  5       2   8    nan
  6       3   4    nan
  7       nan nan  3
  8       nan nan  4
  </code></pre>
  
  <p>Below is what I have tried so far, but its not working. </p>
  
  <pre><code>def impute_unit(cols):
      Legal_Block = cols[0]
      Legal_Lot = cols[1]
      Legal_Unit = cols[2]
  
      if pd.isnull(Legal_Lot):
         return 3
      else:
         return Legal_Unit
  
  bk_Final_tax['Legal_Unit'] = bk_Final_tax[['Legal_Block', 'Legal_Lot', 
                            'Legal_Unit']].apply(impute_unit, axis = 1)
  </code></pre>