title: Pandas dataframe count values above threshold using groupby - code optimization
body: <p>I have a large pandas dataframe where I want to count the number of values above a threshold (zero) in each column grouped by the values in one name column.</p>
  
  <p>The code below does the job, but I wonder if it is unnecessary slow.
  It takes me more than 60 seconds on my computer.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import time
  
  # Set up problem (also slow, but irrelevant at this point)
  n = 40000
  m = 200
  n_name = 1000
  df = pd.DataFrame(np.random.randint(-10, 10, size=(n, m)))
  df['name'] = ''
  for i in range(n):
      df.loc[i, 'name'] = 'Name_' + str(np.random.randint(0, n_name))
  
  
  # Slow code
  t0 = time.time()
  number_above_zero = df.groupby(by='name').apply(lambda x: x[x &gt; 0].count())
  t1 = time.time()
  print('Computation time {} seconds.'.format(np.round(t1 - t0, 1)))
  </code></pre>