title: How to calculate mean after groupby and applying in Python?
body: <p>I'd like to calculate mean(over time which is 5 minute interval) after counting '01''s. What is the best way to do it? </p>
  
  <p>I have aggregated data which is recorded in 5 minute interval. And I would like to calculate mean over the time. Here's the sample dataset.</p>
  
  <pre><code>           captureTime    id           digits
  0  2017-06-26 09:00:00  4015  558460648326103043    
  1  2017-06-26 09:05:00  4015   13721946658181148   
  2  2017-06-26 09:10:00  4015  288298648959188992    
  3  2017-06-26 09:15:00  4015   27023247031744576    
  4  2017-06-26 09:20:00  4015     435887716434584   
  5  2017-06-26 09:25:00  4015          2147614720   
  6  2017-06-26 09:00:00  4014  558451851700273155    
  7  2017-06-26 09:05:00  4014   13721941188808728    
  8  2017-06-26 09:10:00  4014  288263395867623424    
  9  2017-06-26 09:15:00  4014   18016047776938080    
  10 2017-06-26 09:20:00  4014     145547927225032    
  11 2017-06-26 09:25:00  4014          3221356544 
  </code></pre>
  
  <p>Here's my current code:</p>
  
  <pre><code>df_onoff = df_sample.groupby('id')['digits'].apply(lambda nums: "%d" % ', '.join(format(n%2**60,'060b') for n in nums).count('01')).reset_index(name='onoff')
  </code></pre>
  
  <p>And here's the output of df_onoff:</p>
  
  <pre><code>0    34
  1    36
  </code></pre>