title: Pandas dataframe: Create additional column based on date columns comparison
body: <p>Assuming I have the following dataset saved in a Pandas dataframe - note the last column [Status] is the column I'd like to create:</p>
  
  <pre class="lang-none prettyprint-override"><code>Department  Employee    Issue Date  Submission Date ***Status***
  A   Joe 18/05/2014  25/06/2014  0
  A   Joe 1/06/2014   28/06/2014  1
  A   Joe 23/06/2014  30/06/2014  2
  A   Mark    1/03/2015   13/03/2015  0
  A   Mark    23/04/2015  15/04/2015  0
  A   William 15/07/2016  30/07/2016  0
  A   William 1/08/2016   23/08/2016  0
  A   William 20/08/2016  19/08/2016  1
  B   Liz 18/05/2014  7/06/2014   0
  B   Liz 1/06/2014   15/06/2014  1
  B   Liz 23/06/2014  16/06/2014  0
  B   John    1/03/2015   13/03/2015  0
  B   John    23/04/2015  15/04/2015  0
  B   Alex    15/07/2016  30/07/2016  0
  B   Alex    1/08/2016   23/08/2016  0
  B   Alex    20/08/2016  19/08/2016  1
  </code></pre>
  
  <p>I'd like to create an additional column [Status] based on the following conditions:</p>
  
  <ol>
  <li>For every unique [Department] &amp; [Employee] combination (e.g. there are three rows corresponding to Joe in Department A), sort the [Issue Date] from oldest to newest</li>
  <li>If the current row [Issue Date] is greater than <strong>ALL</strong> previous rows [Submission Date], then flag the [Status] with 0; else [Status] = no of times that [Issue Date] &lt; [Submission Date]</li>
  </ol>
  
  <p>As an example: for employee Joe in Department A. When [Issue Date] = '1/06/2014', the previous row's [Submission Date] is after the [Issue Date], therefore [Status] = 1 for row 2. Similarly, when [Issue Date] = '23/06/2014', row 1 &amp; 2's [Submission Date]s are both after the [Issue Date], therefore [Status] = 2 for row 3. We need to perform this calculation for every unique combination of Department and Employee. </p>
  
  <ul>
  <li>Note: real dataset is not sorted nicely as the displayed example.</li>
  </ul>