title: Python dividing time intervals into hourly buckets in
body: <p>I have a dataset as below where each ID can checkin and chekout at any given time and duration</p>
  
  <pre><code>            ID  checkin_datetime    checkout_datetime
              4   04-01-2019 13:07    04-01-2019 13:09
              4   04-01-2019 13:09    04-01-2019 13:12
              4   04-01-2019 14:06    04-01-2019 14:07
              4   04-01-2019 14:55    04-01-2019 15:06
              22  04-01-2019 20:23    04-01-2019 21:32
              22  04-01-2019 21:38    04-01-2019 21:42
              25  04-01-2019 23:22    04-02-2019 00:23
              29  04-02-2019 01:00    04-02-2019 06:15
  </code></pre>
  
  <p>The Checked in minutes computed from this needs to be divided into into hourly buckets as in the following table so that I can compute the cumulative totals by the hour each Id across hours and days even when the checkin check out is taking place across days.</p>
  
  <p>Help appreciated :) </p>
  
  <pre><code>            ID  checkin_datetime    checkout_datetime   day         HR  Minutes
              4   04-01-2019 13:07    04-01-2019 13:09    04-01-2019  13  2
              4   04-01-2019 13:09    04-01-2019 13:12    04-01-2019  13  3
              4   04-01-2019 14:06    04-01-2019 14:07    04-01-2019  14  1
              4   04-01-2019 14:55    04-01-2019 15:06    04-01-2019  14  5
              4   04-01-2019 14:55    04-01-2019 15:06    04-01-2019  15  6
              22  04-01-2019 20:23    04-01-2019 21:32    04-01-2019  20  27
              22  04-01-2019 20:23    04-01-2019 21:32    04-01-2019  21  32
              22  04-01-2019 21:38    04-01-2019 21:42    04-01-2019  21  4
              25  04-01-2019 23:22    04-02-2019 00:23    04-01-2019  23  28
              25  04-01-2019 23:22    04-02-2019 00:23    04-02-2019  0   23
              29  04-02-2019 01:00    04-02-2019 06:15    04-02-2019  1   60
              29  04-02-2019 01:00    04-02-2019 06:15    04-02-2019  2   60
              29  04-02-2019 01:00    04-02-2019 06:15    04-02-2019  3   60
              29  04-02-2019 01:00    04-02-2019 06:15    04-02-2019  4   60
              29  04-02-2019 01:00    04-02-2019 06:15    04-02-2019  5   60
              29  04-02-2019 01:00    04-02-2019 06:15    04-02-2019  6   15
  </code></pre>
  
  <p>Code to create the dataframe:</p>
  
  <pre><code>data={'ID':[4,4,4,4,22,22,25,29],
    'checkin_datetime':['04-01-2019 13:07','04-01-2019 13:09','04-01-2019 14:06','04-01-2019 14:55','04-01-2019 20:23'
    ,'04-01-2019 21:38','04-01-2019 23:22','04-02-2019 01:00'],
    'checkout_datetime':['04-01-2019 13:09','04-01-2019 13:12','04-01-2019 14:07','04-01-2019 15:06','04-01-2019 21:32'
                         ,'04-01-2019 21:42','04-02-2019 00:23'
                         ,'04-02-2019 06:15']
  }
  
  df = DataFrame(data,columns= ['ID', 'checkin_datetime','checkout_datetime'])
  
  df['checkout_datetime'] = pd.to_datetime(df['checkout_datetime'])
  df['checkin_datetime'] = pd.to_datetime(df['checkin_datetime'])
  </code></pre>