title: Pandas Dataframe: How to update multiple columns by applying a function?
body: <p>I have a Dataframe df like this:</p>
  
  <pre><code>   A   B   C    D
  2  1   O   s    h
  4  2   P    
  7  3   Q
  9  4   R   h    m
  </code></pre>
  
  <p>I have a function f to calculate C and D based on B for a row:</p>
  
  <pre><code>def f(p): #p is the value of column B for a row. 
       return p+'k', p+'n'
  </code></pre>
  
  <p>How can I populate the missing values for row 4&amp;7 by applying the function f to the Dataframe?</p>
  
  <p>The expected outcome is like below:</p>
  
  <pre><code>   A   B   C    D
  2  1   O   s    h
  4  2   P   Pk   Pn
  7  3   Q   Qk   Qn
  9  4   R   h    m
  </code></pre>
  
  <p>The function f has to be used as the real function is very complicated. Also, the function only needs to be applied to the rows missing C and D</p>