title: How to calculate time weighted average using Python?
body: <p>So i have data with irregular intervals in a day.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">Event Time</th>
  <th style="text-align: center;">Value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">17-5-2021 03:00</td>
  <td style="text-align: center;">84.9</td>
  </tr>
  <tr>
  <td style="text-align: center;">17-5-2021 11:00</td>
  <td style="text-align: center;">84.9</td>
  </tr>
  <tr>
  <td style="text-align: center;">17-5-2021 15:00</td>
  <td style="text-align: center;">84.7</td>
  </tr>
  <tr>
  <td style="text-align: center;">17-5-2021 23:00</td>
  <td style="text-align: center;">84.7</td>
  </tr>
  <tr>
  <td style="text-align: center;">18-5-2021 03:00</td>
  <td style="text-align: center;">84.5</td>
  </tr>
  <tr>
  <td style="text-align: center;">18-5-2021 11:00</td>
  <td style="text-align: center;">84.5</td>
  </tr>
  <tr>
  <td style="text-align: center;">18-5-2021 15:00</td>
  <td style="text-align: center;">84.9</td>
  </tr>
  <tr>
  <td style="text-align: center;">18-5-2021 23:00</td>
  <td style="text-align: center;">84.9</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to calculate time weighted average using python on the above data as value was only 83.7 for 37.5% (9 hours out of 24) where as if calculate normal average it will be accounted for 50% for 17-5-2021.</p>
  <p>Assumption: If we don't have value for particular interval then last available value is taken eg: value at 17-5-2021 04:00 is 84.9 as that was the last available value.
  Any input would be helpful as I am not able to figure a right way to approach this.
  Expected output:</p>
  <p><a href="https://i.stack.imgur.com/TArPn.png" rel="nofollow noreferrer">Please see the image for Calculation</a></p>
  <p>Final result</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">Event Time</th>
  <th style="text-align: center;">Weighted Average</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">17-5-2021</td>
  <td style="text-align: center;">84.79166</td>
  </tr>
  <tr>
  <td style="text-align: center;">18-5-2021</td>
  <td style="text-align: center;">84.71666</td>
  </tr>
  </tbody>
  </table>
  </div>