title: Create a new column containing time since last event in pandas
body: <p>I have a pandas dataframe with the following structure:</p>
  
  <pre><code>ID    date           event_1   event_2 
   1    2016-01-03     False     False
        2016-02-07     True      False
        2016-02-18     False     True
   2    2016-01-01     False     True
        2016-01-04     False     False
        2016-02-02     True      False
        2016-02-04     False     False
        2016-02-05     False     True
  </code></pre>
  
  <p><code>ID</code> and <code>date</code> are a <code>MultiIndex</code>.</p>
  
  <p>The question is, I want to create two new  columns <code>time_1</code> and <code>time_2</code>. Those columns should show the time elapsed since the corresponding event, e.g. </p>
  
  <pre><code>ID    date           event_1     event_2   time_1    time_2
   1    2016-01-03     False       False     -          -
        2016-02-07     True        False     0          -
        2016-02-18     False       True      11         0
   2    2016-01-01     False       True      -          0
        2016-01-04     False       False     -          3
        2016-02-02     True        False     0          32
        2016-02-04     False       False     2          34
        2016-02-05     False       True      3          0
  </code></pre>
  
  <p>How can I create a function that calculates this in <code>pandas</code>, given that the date is an index?</p>
  
  <p>The calculations are per <code>ID</code> and the events are unrelated. </p>