Last active
February 11, 2021 19:00
-
-
Save thepycoach/2e0dcbf5a53ba26a701042d7bc2625c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #loop through each league | |
| for league in dict_historical_data: | |
| #picking unique team names inside the historical_data team names | |
| all_teams = dict_historical_data[league]['home_team'].unique().tolist() | |
| #matching betfair names (dict_betfair -> dict_home_name_matching, dict_away_name_matching) with historical data (dict_historical_data -> all_teams) | |
| dict_home_name_matching[league][['teams_matched', 'score']] = dict_home_name_matching[league]['home_team'].apply(lambda x:process.extractOne(x, all_teams, scorer=fuzz.token_set_ratio)).apply(pd.Series) | |
| dict_away_name_matching[league][['teams_matched', 'score']] = dict_away_name_matching[league]['away_team'].apply(lambda x:process.extractOne(x, all_teams, scorer=fuzz.token_set_ratio)).apply(pd.Series) | |
| #Replacing "Historical Data" team names (teams_matched) in betfair dataframes | |
| home_teams = pd.merge(dict_betfair[league], dict_home_name_matching[league], on='home_team', | |
| how='left')[['Dates', 'over2.5', 'btts', 'teams_matched']].rename(columns={'teams_matched':'home_team'}) | |
| away_teams = pd.merge(dict_betfair[league], dict_away_name_matching[league], on='away_team', | |
| how='left')[['teams_matched']].rename(columns={'teams_matched':'away_team'}) | |
| #updating values | |
| dict_betfair.update({league:pd.concat([home_teams, away_teams], axis=1)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment