title: How to apply a custom formula over a group element in a grouped.apply().unstack() method?
body: <p>I'm using a version of this recipe in 'Python for Data analysis' p.269</p>
  
  <pre><code>frame = DataFrame({'data1': np.random.randn(1000),
                     'data2': np.random.randn(1000)})
  factor = pd.cut(frame.data1, 4)
  def get_stats(group):
     return {'min': group.min(), 'max': group.max(),
             'count': group.count(), 'mean': group.mean()}
  grouped = frame.data2.groupby(factor)
  grouped.apply(get_stats).unstack()
  
  Out[101]:
                  count      max      mean       min
  data1
  (-1.23, 0.489]    598 3.260383 -0.002051 -2.989741
  (-2.956, -1.23]    95 1.670835 -0.039521 -3.399312
  (0.489, 2.208]    297 2.954439  0.081822 -3.745356
  (2.208, 3.928]     10 1.765640  0.024750 -1.929776
  </code></pre>
  
  <p>In the part where the formula get_stats(group) gets defined I want to include a function that counts the number of positive observations and divides them by the total number of observations. So I tried</p>
  
  <pre><code>def get_stats(group):
      return {'mean': group.mean(), 'std': group.std(),
              'hit_r': group.applymap(lambda x: x &gt;= 0).sum() / group.count()}
  </code></pre>
  
  <p>However I got:</p>
  
  <pre><code>AttributeError: 'Series' object has no attribute 'applymap'
  </code></pre>
  
  <p>How can I find a way to incorporate that calculation over a group?</p>
  
  <p>Thanks</p>