title: Creating missing time ranges in pandas
body: <p>I have a pandas dataframe where each row corresponds to a period of time for a given record. If a record has more than one period of time there is a gap between them. I would like to fill in all the missing time periods that are between the end of the first time period and the start of the final time period.</p>
  <p>My data looks like this:</p>
  <pre><code>record = [1, 1, 2, 2, 2]
  start_time = pd.to_datetime(['2001-01-01', '2001-02-01', '2000-01-01', '2001-05-31', '2001-09-01'])
  stop_time = pd.to_datetime(['2001-01-15', '2001-02-28', '2001-01-31', '2001-08-16', '2001-09-30'])
  df = pd.DataFrame({'record': record, 'start_time': start_time, 'stop_time': stop_time})
  
     record start_time  stop_time
  0       1 2001-01-01 2001-01-15
  1       1 2001-02-01 2001-02-28
  2       2 2000-01-01 2001-01-31
  3       2 2001-05-31 2001-08-16
  4       2 2001-09-01 2001-09-30
  
  </code></pre>
  <p>The gaps in time are between lines 0 and 1 (the stop time is 2001-01-15 and the next start time is 2001-02-01, which is a 16 day gap), as well as 2 and 3, and 3 and 4. Gaps can only happen between the first and last row for a given record.</p>
  <p>What I'm trying to achieve is this:</p>
  <pre><code>   record start_time  stop_time
  0       1 2001-01-01 2001-01-15
  1       1 2001-01-16 2001-01-31
  2       1 2001-02-01 2001-02-28
  3       2 2000-01-01 2001-01-31
  4       2 2001-02-01 2001-05-30
  5       2 2001-05-31 2001-08-16
  6       2 2001-08-17 2001-08-31
  7       2 2001-09-01 2001-09-30
  </code></pre>
  <p>That is, I want to add in rows that have start and stop times that fit those gaps. So in the previous example there would be a new row for record 1 with a start date of 2001-01-16 and an end date of 2001-01-31.</p>
  <p>The full dataset has over 2M rows across 1.5M records, so I'm looking for a vectorized solution in pandas that doesn't use apply and is relatively efficient.</p>