title: Mean for column based on time
body: <p>I have two dataframes. The first one has timepoints and values for different measurements.
  df1:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>time</th>
  <th>valueX</th>
  <th>valueY</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2021-05-05 11:27:25</td>
  <td>10</td>
  <td>3</td>
  </tr>
  <tr>
  <td>2021-06-05 11:27:25</td>
  <td>15</td>
  <td>5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>and a second dataframe with a lot of temperature measurements.
  df2:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>time</th>
  <th>temp</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2021-05-05 11:25:25</td>
  <td>20.1</td>
  </tr>
  <tr>
  <td>2021-05-05 11:35:25</td>
  <td>20.2</td>
  </tr>
  <tr>
  <td>2021-05-05 11:45:25</td>
  <td>20.1</td>
  </tr>
  <tr>
  <td>2021-05-05 11:55:25</td>
  <td>21.2</td>
  </tr>
  <tr>
  <td>2021-05-05 12:05:25</td>
  <td>20.1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I would like to have another column in df1 that gives me the mean temperature of the last 3 days for the timepoint in column 1 of df1. And I have no glue how to do that...
  I tried something like this</p>
  <pre><code>df1['mean_tepm'] = df2[(df1['time']-df2['time'] &lt; timedelta(days=3) &amp; (df2[(df1['time']-df2['time'] &lt; timedelta(days=0)]['temperature'].mean()
  </code></pre>
  <p>But it gave me the same value for every row.</p>