title: How to calculate new Pandas dataframe column with different functions according to other column entries?
body: <p>Given this dataframe</p>
  
  <pre><code>df=pd.DataFrame({"A":[0.380,0.475,0.380,0.475,0.570],"B":[20,20,63,63,63]})
  
         A     B
  0    0.380   20
  1    0.475   20
  2    0.380   63
  3    0.475   63
  4    0.570   63
  </code></pre>
  
  <p>I would like to add a column that returns the result of a function given the input of column A, but the function should vary based on the content of column B. Easy enough to add a column based on A using the apply method:</p>
  
  <pre><code>def conv(x):
      return (33.8*np.sin(1.65*(x-0.89))+33.9)/0.19
  df['C']=df['A'].apply(conv)
  df
  </code></pre>
  
  <p>but I'd like to apply a completely different function to A based on the entry in column B. Setting up any 'if' statements within the definition returns ValueErrors of course, and using <code>df['C'].isin([20])</code> gives me a list of boolean values. Next I'm going to try <code>df.groupby('B')</code> and apply different functions to each group, but I'm still wondering what is the most elegant solution.  </p>