title: Count number of games of a teams last 10 days
body: <p>I tried to create a field that count the number of games played by a team in the past 10 days.</p>
  
  <p>My dataset is like this :</p>
  
  <pre><code>date              Home     Visitors    Result
  2020-01-01        Paris     Lisbon       1
  2020-01-03        Madrid    London       1
  2020-01-13        Lisbon    Madrid       1
  2020-01-14        London    Paris        1
  </code></pre>
  
  <p>I want to create <code>df['home_last_games']</code> containing the number of games played by the home team past 10 days. And same for <code>df['visitor_last_games']</code> containing the number of games played by the visitor team past 10 days.</p>
  
  <p>Each field should sum the past few games either the team played home or away.</p>
  
  <p>Expected result here is :</p>
  
  <pre><code>date              Home    Visitors    Result    Home_last_games    Visitors_last_games
  2020-01-01        Paris     Lisbon       1             1                       1
  2020-01-03        Madrid    London       1             1                       1
  2020-01-13        Lisbon    Madrid       1             1                       2
  2020-01-14        London    Paris        1             1                       1
  </code></pre>
  
  <p>For now here is my code :</p>
  
  <pre><code>teams = df['home'].unique()
  
  for team in teams:
      day = df['date'] - timedelta(days=10)
      df['home_last_games'] = df.loc[(df['home'] == team) &amp; (df['date'] &gt;= day), 'home'].count()
      df['visitor_last_games'] = df.loc[(df['visitor'] == team) &amp; (df['date'] &gt;= day), 'visitor'].count()
  </code></pre>
  
  <p>But this not working. </p>
  
  <p>Thank you for your help. </p>
  
  <p>Regards, </p>