title: Add a sequence number to each element in a group using python
body: <p>I have a dataframe of individuals who each have multiple records.  I want to enumerate the record in the sequence for each individual in python.  Essentially I would like to create the 'sequence' column in the following table:</p>
  <pre class="lang-none prettyprint-override"><code>patient  date      sequence
  145      20Jun2009        1
  145      24Jun2009        2
  145      15Jul2009        3
  582      09Feb2008        1
  582      21Feb2008        2
  987      14Mar2010        1
  987      02May2010        2
  987      12May2010        3
  </code></pre>
  <p>This is essentially the same question as <a href="https://stackoverflow.com/questions/10244594/how-to-add-sequence-number-for-each-element-in-a-group-using-a-sql-query-without">here</a>, but I am working in python and unable to implement the sql solution. I suspect I can use a groupby statement with an iterable count, but have so far been unsuccessful.</p>