title: Pandas DataFrame: how to get column mean valuebut taking into account only the rows that have lower index than the one I want to get the mean
body: <p>The problem I have is I want to predict the victory of a team over another one, to do that I want to have for each match the winrate of each team before the date of the match.</p>
  
  <p>However using a <code>df.groupBy("teamName").agg({"isVictory":"mean"})</code> provides me the global wirate of the team that is not usable because you are not supposed to know the winrate of all matches at this instant.</p>
  
  <p>So what I would like, is to get the winrate of the matches before this one, knowing that I have a column <code>index</code> in my DataFrame that keep the order of the match (i.e. if the index of a match is lower than the index of the current match it means the match has been made before, thus this match should be considered in the mean)</p>
  
  <p>Note that my columns are :</p>
  
  <blockquote>
    <p>indexMatch, nameTeam, isVictoryTeam</p>
  </blockquote>
  
  <p>(isVictoryTeam= if Team1 won and 0 if the Team lost )</p>
  
  <p>an example of the dataset: </p>
  
  <pre><code>   IndexMatch  isVictoryTeam team   winrate
  0           1              1    a       NaN
  1           2              0    a         1
  2           3              1    a       0.5
  3           4              1    a    0.6667
  </code></pre>
  
  <p>The winrate is the output expected.<br>
  Thank you in advance for your help.</p>