Skip to content

Instantly share code, notes, and snippets.

@thepycoach
Last active February 11, 2021 19:09
Show Gist options
  • Select an option

  • Save thepycoach/0cbac60b60f423cd5d0be5d3796941fe to your computer and use it in GitHub Desktop.

Select an option

Save thepycoach/0cbac60b60f423cd5d0be5d3796941fe to your computer and use it in GitHub Desktop.
#inputs
match_date = '2021-02-14'
dict_filter = {'goals':2.5, 'shots_target':9, 'corners':9}
#-----------------------------------
#concatenate all leagues in dict_betfair
df_betfair = pd.concat(dict_betfair, ignore_index=True)
df_betfair = df_betfair[df_betfair['Dates']==match_date]
#split home and away teams
home = df_betfair['home_team'].to_list()
away = df_betfair['away_team'].to_list()
goals = []
shots_target = []
corners = []
promoted_team = [] #no stats available (promoted teams that don't have stats available in the recent 2 years)
#calculating and storing stats (average goals, total shots on target and total corners)
for home_team, away_team in zip(home, away):
try:
goals.append(round((df_stats.loc[home_team, 'home_goals'] + df_stats.loc[away_team, 'away_goals'])/2, 2))#betpractice method
shots_target.append(df_stats.loc[home_team, 'home_shots_target'] + df_stats.loc[away_team, 'away_shots_target'])
corners.append(df_stats.loc[home_team, 'home_corners'] + df_stats.loc[away_team, 'away_corners'])
except:
print('Possible promoted teams: '+home_team+' - '+away_team) #no stats data
goals.append(0)
shots_target.append(0)
corners.append(0)
#filtering games out
df_filters = pd.DataFrame.from_dict({'home_team':home, 'away_team':away, 'goals':goals,
'shorts_target':shots_target, 'corners':corners})
df_filters = df_filters[(df_filters['goals']>=dict_filter['goals']) &
(df_filters['shorts_target']>=dict_filter['shots_target']) &
(df_filters['corners']>=dict_filter['corners'])]
df_filters = pd.merge(df_betfair, df_filters, on=['home_team', 'away_team'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment