I have a dataset that consists of all the shots taken in a large number of football competitions for a number of seasons. I wrote the following script to make subsets for each competition and corresponding season.
import pandas as pd
import csv
shots = pd.read_csv("C:/Users/HJA/Desktop/Betting/understatV0.01/shots.csv", encoding='iso-8859-1')
shots_premier_league = shots.groupby(['Competition']).get_group('Premier_League')
shots_bundesliga = shots.groupby(['Competition']).get_group('Bundesliga')
shots_la_liga = shots.groupby(['Competition']).get_group('La_Liga')
shots_ligue_1 = shots.groupby(['Competition']).get_group('Ligue_1')
shots_serie_a = shots.groupby(['Competition']).get_group('Serie_A')
Everything goes fine until this point. However, now I want to subdivide each competition in samples for each season. I use the following script (in this case I use as example the Premier League:
shots_premier_league_2014 = shots_premier_league.groupby(['Season']).get_group('2014')
shots_premier_league_2015 = shots_premier_league.groupby(['Season']).get_group('2015')
shots_premier_league_2016 = shots_premier_league.groupby(['Season']).get_group('2016')
shots_premier_league_2017 = shots_premier_league.groupby(['Season']).get_group('2017')
shots_premier_league_2018 = shots_premier_league.groupby(['Season']).get_group('2018')
This result in the following error:
I am 100% sure that 2014 is an actual value. In addition, how can I write a function that automatically includes the competition and season in the name of the pandas dataframe?