title: Calculated DataFrame column by a column condition
body: <p>I'm new in Python and I'm trying to calculate a new column of a DataFrame based on a condition by another column of the same dataframe.</p>
  
  <p>I have a DataFrame with the columns A, B, C, D, E.</p>
  
  <p>I need to calculate new column F:</p>
  
  <pre><code>F = A - B if E == 'Y'
  F = A - (C + D) if E == 'N'
  </code></pre>
  
  <p>I tried to use the function <code>Apply</code> but it doesn't work.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def my_funcion(column): 
      if column == 'N' :
          return df['B']
      if column== 'Y' :
          return (df['C'] + df['D'])
  df['F'] = df['A'] - df.apply(myfunction(df['E'], axis=1) 
  </code></pre>
  
  <p>But it shows me this error:</p>
  
  <blockquote>
    <p>ValueError: ('The truth value of a Series is ambiguous. Use a.empty, 
        a.bool(), a.item(), a.any() or a.all().', u'occurred at index 0'</p>
  </blockquote>