title: How to apply function to every row in a pandas dataframe that requires multiple rows in the calculation?
body: <p>Just an example...
  I have a 5M row dataframe full of runners and a log of how many miles they ran on any given day. If a runner doesn't run on a day, there is no 0 entry.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Runner</th>
  <th>Day</th>
  <th>Miles</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>1</td>
  <td>3</td>
  </tr>
  <tr>
  <td>A</td>
  <td>3</td>
  <td>4</td>
  </tr>
  <tr>
  <td>A</td>
  <td>8</td>
  <td>4</td>
  </tr>
  <tr>
  <td>A</td>
  <td>9</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I'm trying to get a field for how much they ran in the last 7 calendar days (not including the current row), as well as the next 7 calendar days (including current row).</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Runner</th>
  <th>Day</th>
  <th>Miles</th>
  <th>Last 7</th>
  <th>Next 7</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>1</td>
  <td>3</td>
  <td>null</td>
  <td>7</td>
  </tr>
  <tr>
  <td>A</td>
  <td>3</td>
  <td>4</td>
  <td>3</td>
  <td>10</td>
  </tr>
  <tr>
  <td>A</td>
  <td>8</td>
  <td>4</td>
  <td>7</td>
  <td>6</td>
  </tr>
  <tr>
  <td>A</td>
  <td>9</td>
  <td>2</td>
  <td>10</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I think can get the answer for a single row.</p>
  <p>Next 7 for row 1 for example...</p>
  <p>df.loc[(df['Runner'] == 'A') &amp; (df['day'] &gt;= 1) &amp; (df['day'] &lt; 1+7)]['Miles'].sum()</p>
  <p>I'm just unsure how to apply this type of thing to every row in an efficient way. The methods I've seen so far only utilize data from the same row. Any help?</p>