title: Python - faster ways to count the number of DataFrame rows with criteria?
body: <p>I'd like to count the number of pandas DataFrame rows in each bin and make a list of the counts.</p>
  
  <p>I think there should be faster ways than mine. Could you give me some advice?</p>
  
  <p><strong>script.py</strong></p>
  
  <pre><code>import pandas
  
  binwidth = 10
  data = pandas.read_csv('sample.csv', sep=' ', names=['time', 'value'], header=None, comment='#')
  
  mylist = []
  
  for item in data.iterrows():
      index = item[1]['time']/binwidth
      if len(mylist) &lt;= index:
          mylist.append(1)
      else:
          mylist[index] += 1
  
  print mylist # which outputs [8, 4, 4]
  </code></pre>
  
  <p><strong>sample.csv</strong></p>
  
  <pre><code># time value
  1 a
  2 b
  3 c
  4 d
  6 e
  7 f
  8 g
  9 h
  10 i
  12 j
  15 k
  17 l
  21 m
  22 n
  26 o
  29 p
  </code></pre>