Count values in column up to and including the current row in a rolling fashion

I am looking to get calculate the field in my data from Home Team Home Games Count.

I've created the function below but know it isn't right. I then want to apply it to my table as below.

Any help is greatly appreciated

 def home_team_home_games(row):
      return count.Home_team

 df['home_team_home_games_count'] = df.apply(home_team_home_games, axis=1)
HomeTeam Away Team Home Team Home Games Count
Arsenal Chelsea 1
Chelsea Man Utd 1
Man Utd Chelsea 1
Chelsea Arsenal 2
Man Utd Arsenal 2

Read more here:

Content Attribution

This content was originally published by David27 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: