title: Use Apply on a SeriesGroupBy Object where conditions are met
body: <p>I have a DataFrame <code>df1</code>: </p>
  
  <pre><code> df1.head() = 
  
             id      ret     eff
      1469  2300 -0.010879  4480.0
      328   2300 -0.000692 -4074.0
      1376  2300 -0.009551  4350.0
      2110  2300 -0.014013  5335.0
      849   2300 -0.286490 -9460.0
  </code></pre>
  
  <p>I would like to create a new column that contains the normalized values of the column <code>df1['eff']</code>.<br>
  In other words, I would like to group <code>df1['eff']</code>by <code>df1['id']</code>, look for the max value (<code>mx = df1['eff'].max()</code>) and the min value (<code>mn = df2['eff'].min()</code>), and divide in a pairwise fashion each value of the column <code>df1['eff']</code>by <code>mn</code>or <code>mx</code> depending if <code>df1['eff'] &gt; 0</code> or  <code>df1['eff']&lt; 0</code>.</p>
  
  <p>The code that I have written is the following: </p>
  
  <pre><code>df1['normd'] = df1.groupby('id')['eff'].apply(lambda x: x/x.max() if x &gt; 0 else x/x.min())
  </code></pre>
  
  <p>However python throws the following error:</p>
  
  <pre><code>*** ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(),
   a.item(), a.any() or a.all().
  </code></pre>
  
  <p>Since <code>df1.groupby('id')['eff']</code> is a <code>SeriesGroupBy Object</code>, i decided to use <code>map()</code>. 
  But again python throws the following error: </p>
  
  <pre><code> *** AttributeError: Cannot access callable attribute 'map' of 'SeriesGroupBy' ob
   jects, try using the 'apply' method
  </code></pre>
  
  <p>Many thanks in advance.</p>