title: For a column in pandas dataframe, calculate mean of column values in previous 4th, 8th and 12th row from the present row?
body: <p>In a pandas dataframe, I want to create a new column that calculates the average of column values of 4th, 8th and 12th row <strong>before</strong> our present row.</p>
  <p>As shown in the table below, for row number 13 :</p>
  <p>Value in <strong>Existing column</strong> that is 4 rows before row 13 (row 9) = 4</p>
  <p>Value in <strong>Existing column</strong> that is 8 rows before row 13 (row 5) = 6</p>
  <p>Value in <strong>Existing column</strong> that is 12 rows before row 13 (row 1) = 2</p>
  <p>Average of 4,6,2 is 4. Hence <strong>New Column = 4</strong> at row number 13, for the remaining rows between 1-12, <strong>New Column = Nan</strong></p>
  <p>I have more rows in my df, but I added only first 13 rows here for illustration.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Row number</th>
  <th>Existing column</th>
  <th>New column</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>2</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>2</td>
  <td>4</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>3</td>
  <td>3</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>4</td>
  <td>1</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>5</td>
  <td>6</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>6</td>
  <td>4</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>7</td>
  <td>8</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>8</td>
  <td>2</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>9</td>
  <td>4</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>10</td>
  <td>9</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>11</td>
  <td>2</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>12</td>
  <td>4</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>13</td>
  <td>3</td>
  <td>3</td>
  </tr>
  </tbody>
  </table>
  </div>