title: How can I compute the rolling mean of a column for a set period of time, using Pandas and groupby, given a specific condition?
body: <p>This is a variation of <a href="https://stackoverflow.com/questions/69985613/how-can-i-compute-the-rolling-mean-of-a-column-for-a-set-period-of-time-using-p">this question</a>, only with a new column, <code>Track</code>:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Date</th>
  <th>Jockey ID</th>
  <th>Position</th>
  <th>Track</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>23-12-2018</td>
  <td>4340</td>
  <td>1</td>
  <td>Sha Tin</td>
  </tr>
  <tr>
  <td>25-11-2018</td>
  <td>4340</td>
  <td>5</td>
  <td>Sha Tin</td>
  </tr>
  <tr>
  <td>19-12-2018</td>
  <td>4340</td>
  <td>10</td>
  <td>Happy Valley</td>
  </tr>
  <tr>
  <td>01-01-2019</td>
  <td>4340</td>
  <td>3</td>
  <td>Happy Valley</td>
  </tr>
  <tr>
  <td>18-10-2017</td>
  <td>8443</td>
  <td>1</td>
  <td>Sha Tin</td>
  </tr>
  <tr>
  <td>18-02-2018</td>
  <td>8443</td>
  <td>6</td>
  <td>Sha Tin</td>
  </tr>
  <tr>
  <td>12-05-2018</td>
  <td>8443</td>
  <td>7</td>
  <td>Happy Valley</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>What I am looking for is a way to compute the rolling mean final position, in the last 1000 days, on a specifically on Sha Tin. The final result:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Date</th>
  <th>Jockey ID</th>
  <th>Position</th>
  <th>Track</th>
  <th>Mean Position</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>23-12-2018</td>
  <td>4340</td>
  <td>1</td>
  <td>Sha Tin</td>
  <td>1 (1/1)</td>
  </tr>
  <tr>
  <td>25-11-2018</td>
  <td>4340</td>
  <td>5</td>
  <td>Sha Tin</td>
  <td>3 (1+5)/2</td>
  </tr>
  <tr>
  <td>19-12-2018</td>
  <td>4340</td>
  <td>10</td>
  <td>Happy Valley</td>
  <td></td>
  </tr>
  <tr>
  <td>01-01-2019</td>
  <td>4340</td>
  <td>3</td>
  <td>Happy Valley</td>
  <td></td>
  </tr>
  <tr>
  <td>18-10-2017</td>
  <td>8443</td>
  <td>1</td>
  <td>Sha Tin</td>
  <td>1 (1/1)</td>
  </tr>
  <tr>
  <td>18-02-2018</td>
  <td>8443</td>
  <td>6</td>
  <td>Sha Tin</td>
  <td>3.5 (1+6)/2</td>
  </tr>
  <tr>
  <td>12-05-2018</td>
  <td>8443</td>
  <td>7</td>
  <td>Happy Valley</td>
  <td></td>
  </tr>
  </tbody>
  </table>
  </div>