title: Python Pandas: Counting element occurrences in series
body: <p>How to find series element counts? Using this code:</p>
  
  <pre><code>import pandas as pd
  
  d = { 'x' : [1,2,2,2,3,4,5,5,7] }
  df = pd.DataFrame(d)
  cnt1 = len(df[df.x == 1])
  cnt2 = len(df[df.x == 2])
  cnt3 = len(df[df.x == 3])
  ...
  </code></pre>
  
  <p>does not help much. Is there any way to count element occurrences so result would be a dictionary with 'element, count' pairs, like this:</p>
  
  <pre><code>cnts = {'1':1, '2': 3, '3':1, ...}
  </code></pre>
  
  <p>or in some other structure easy to lookup and iterate ?</p>