title: How to write a for loop from specific row?
body: <p>I am trying to predict the premiere league. I am using moving average for getting the new season's team home shot, away shot and fouls. I wrote a function for moving average but I am not able to put it in a for loop so that it can utilize the function to auto populate those columns. I tried but it is not working.</p>
  <pre><code>def get_avg_stats_last_n_games(team, game_date, n):
      prev_game_df = (
          prem_league[prem_league[&quot;Date&quot;] &lt; game_date][
              (prem_league[&quot;HomeTeam&quot;] == team)
              | (prem_league[&quot;AwayTeam&quot;] == team)
          ]
          .sort_values(by=&quot;Date&quot;)
          .tail(n)
      )
  
      h_df = prev_game_df.iloc[:, range(2, 20, 2)]
      h_df.columns = [
          &quot;Team&quot;,
          &quot;Fulltime G&quot;,
          &quot;Halftime G&quot;,
          &quot;shots&quot;,
          &quot;shots on target&quot;,
          &quot;foul&quot;,
          &quot;corner&quot;,
          &quot;yellow&quot;,
          &quot;red&quot;,
      ]
      a_df = prev_game_df.iloc[:, range(3, 21, 2)]
      a_df.columns = [
          &quot;Team&quot;,
          &quot;Fulltime G&quot;,
          &quot;Halftime G&quot;,
          &quot;shots&quot;,
          &quot;shots on target&quot;,
          &quot;foul&quot;,
          &quot;corner&quot;,
          &quot;yellow&quot;,
          &quot;red&quot;,
      ]
  
      df = pd.concat([h_df, a_df])
      df = df[df[&quot;Team&quot;] == team]
      df.drop(columns=[&quot;Team&quot;], inplace=True)
  
      return df.mean().round()
  </code></pre>
  <p>this is the for loop for auto populating the table with the help of moving average from the row I want to predict the shots, foul and others:</p>
  <pre><code>for index, row in prem_league4.iloc[3840:].iterrows():
      
      game_date = row['Date']
      h_team = row['HomeTeam']
      a_team = row['AwayTeam']
      
      aa = get_avg_stats_last_n_games(a_team, game_date, 20)
      prem_league4['AS'] = aa[4]
  </code></pre>
  <p>can someone help me write the loop?</p>
  <p><a href="https://i.stack.imgur.com/xKByi.png" rel="nofollow noreferrer">The table that I want to populate</a>.</p>
  <p>I want to fill the NA's in this table with the function I create for that I was trying to use for loop but I am not able to figure out how to do it. The table is filled till the row 3839 and I want to start the for loop from row number 3840 and populate the home and away shots with moving average function in the for loop.</p>