title: How to discretize time series with overspilling durations?
body: <p>I am trying to discretize my dataframe which looks like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th></th>
  <th>Start Date</th>
  <th>Park Duration (mins)</th>
  <th>Charge Duration (mins)</th>
  <th>Energy (kWh)</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>49698</td>
  <td>2016-01-01 11:48:00</td>
  <td>230</td>
  <td>92.0</td>
  <td>3.034643</td>
  </tr>
  <tr>
  <td>49710</td>
  <td>2016-01-01 13:43:00</td>
  <td>225</td>
  <td>225.0</td>
  <td>12.427662</td>
  </tr>
  <tr>
  <td>49732</td>
  <td>2016-01-01 22:43:00</td>
  <td>708</td>
  <td>111.0</td>
  <td>10.752058</td>
  </tr>
  <tr>
  <td>49736</td>
  <td>2016-01-02 07:09:00</td>
  <td>149</td>
  <td>149.0</td>
  <td>11.160776</td>
  </tr>
  <tr>
  <td>49745</td>
  <td>2016-01-02 10:29:00</td>
  <td>156</td>
  <td>156.0</td>
  <td>10.298505</td>
  </tr>
  <tr>
  <td>49758</td>
  <td>2016-01-02 13:06:00</td>
  <td>84</td>
  <td>84.0</td>
  <td>2.904127</td>
  </tr>
  <tr>
  <td>49768</td>
  <td>2016-01-02 15:00:00</td>
  <td>27</td>
  <td>26.0</td>
  <td>2.573858</td>
  </tr>
  <tr>
  <td>49773</td>
  <td>2016-01-02 15:31:00</td>
  <td>174</td>
  <td>152.0</td>
  <td>14.961943</td>
  </tr>
  <tr>
  <td>49775</td>
  <td>2016-01-02 16:01:00</td>
  <td>195</td>
  <td>167.0</td>
  <td>16.317518</td>
  </tr>
  <tr>
  <td>49790</td>
  <td>2016-01-02 19:37:00</td>
  <td>108</td>
  <td>108.0</td>
  <td>10.829344</td>
  </tr>
  <tr>
  <td>49791</td>
  <td>2016-01-02 19:56:00</td>
  <td>289</td>
  <td>26.0</td>
  <td>2.552439</td>
  </tr>
  <tr>
  <td>49802</td>
  <td>2016-01-03 09:23:00</td>
  <td>58</td>
  <td>58.0</td>
  <td>5.243358</td>
  </tr>
  <tr>
  <td>49803</td>
  <td>2016-01-03 09:33:00</td>
  <td>264</td>
  <td>134.0</td>
  <td>6.782309</td>
  </tr>
  <tr>
  <td>49813</td>
  <td>2016-01-03 11:12:00</td>
  <td>240</td>
  <td>0.0</td>
  <td>0.008115</td>
  </tr>
  <tr>
  <td>49825</td>
  <td>2016-01-03 14:12:00</td>
  <td>97</td>
  <td>96.0</td>
  <td>5.29069</td>
  </tr>
  <tr>
  <td>49833</td>
  <td>2016-01-03 15:52:00</td>
  <td>201</td>
  <td>201.0</td>
  <td>16.058235</td>
  </tr>
  <tr>
  <td>49834</td>
  <td>2016-01-03 15:52:00</td>
  <td>53</td>
  <td>52.0</td>
  <td>5.304866</td>
  </tr>
  <tr>
  <td>49840</td>
  <td>2016-01-03 17:27:00</td>
  <td>890</td>
  <td>219.0</td>
  <td>15.878921</td>
  </tr>
  <tr>
  <td>49857</td>
  <td>2016-01-04 05:57:00</td>
  <td>198</td>
  <td>127.0</td>
  <td>6.368932</td>
  </tr>
  <tr>
  <td>49871</td>
  <td>2016-01-04 08:48:00</td>
  <td>75</td>
  <td>74.0</td>
  <td>5.99877</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>What I want to do is to sample it in to 2 hour slots, like so:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Start Date</th>
  <th>Energy (kWh)</th>
  <th>Charge Duration (mins)</th>
  <th>Fee</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2016-01-01 10:00:00</td>
  <td>3.034643</td>
  <td>92.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-01 12:00:00</td>
  <td>12.427662</td>
  <td>225.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-01 14:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-01 16:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-01 18:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-01 20:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-01 22:00:00</td>
  <td>10.752058</td>
  <td>111.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-02 00:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-02 02:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  <tr>
  <td>2016-01-02 04:00:00</td>
  <td>0.0</td>
  <td>0.0</td>
  <td>0.0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Which i did with</p>
  <pre><code>data.resample('2H', on='Start Date').agg(({'Energy (kWh)':'sum','Charge Duration (mins)':'sum'}))
  </code></pre>
  <p>However the problem is that there is overspilling in the data, as you can see from the first row, the Charge Duration is 92 mins. however only 12 of those 92 minutes is in the 10:00:00 - 12:00:00 time slot, however the way i used resample assigned all of the charge duration to that time slot. The behaviour I want is to split them &quot;evenly&quot; in the timeslots based on Start Date and Charge Duration, such that 12 minutes fall in to the first slot and the remaining 80 falls into the next. There is also instances of EV chargings going over 3 periods. I hope it makes sense.
  How would you go about it?</p>
  <p>Here is the original data as comma seperated values:</p>
  <p>,Start Date,Park Duration (mins),Charge Duration (mins),Energy (kWh)
  49698,2016-01-01 11:48:00, 230 ,92.0,3.034643
  49710,2016-01-01 13:43:00, 225 ,225.0,12.427662
  49732,2016-01-01 22:43:00, 708 ,111.0,10.752058
  49736,2016-01-02 07:09:00, 149 ,149.0,11.160776
  49745,2016-01-02 10:29:00, 156 ,156.0,10.298505
  49758,2016-01-02 13:06:00, 84 ,84.0,2.904127
  49768,2016-01-02 15:00:00, 27 ,26.0,2.573858
  49773,2016-01-02 15:31:00, 174 ,152.0,14.961943
  49775,2016-01-02 16:01:00, 195 ,167.0,16.317518
  49790,2016-01-02 19:37:00, 108 ,108.0,10.829344
  49791,2016-01-02 19:56:00, 289 ,26.0,2.552439
  49802,2016-01-03 09:23:00, 58 ,58.0,5.243358
  49803,2016-01-03 09:33:00, 264 ,134.0,6.782309
  49813,2016-01-03 11:12:00, 240 ,0.0,0.008115
  49825,2016-01-03 14:12:00, 97 ,96.0,5.29069
  49833,2016-01-03 15:52:00, 201 ,201.0,16.058235
  49834,2016-01-03 15:52:00, 53 ,52.0,5.304866
  49840,2016-01-03 17:27:00, 890 ,219.0,15.878921
  49857,2016-01-04 05:57:00, 198 ,127.0,6.368932
  49871,2016-01-04 08:48:00, 75 ,74.0,5.99877</p>