You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you try to scrap a game from WhoScored using the package, with a 0-0 score, a KeyError occurs.
Within the file whoscored.py at line 676, the process try to access the feature 'is_goal', which seems to not exist if the score at the end of the game is 0-0.
A solution could be to check if all the necessary features are indeed part of the dataframe, and if not, add it with np.nan values.
The python code could be as follow, before the line 676 :
Hello everyone,
If you try to scrap a game from WhoScored using the package, with a 0-0 score, a KeyError occurs.
Within the file whoscored.py at line 676, the process try to access the feature 'is_goal', which seems to not exist if the score at the end of the game is 0-0.
Example of game where this issue happen : https://www.whoscored.com/Matches/1640849/Live/England-Premier-League-2022-2023-Newcastle-Leeds
Python code :
import soccerdata as sd
ws = sd.WhoScored(leagues="ENG-Premier League", seasons="22-23")
events = ws.read_events(match_id=1640849)
Error :
KeyError:
['is_goal'] not in index
A solution could be to check if all the necessary features are indeed part of the dataframe, and if not, add it with np.nan values.
The python code could be as follow, before the line 676 :
Python code :
cols = ['event_id', 'expanded_minute', 'is_touch', 'minute', 'outcome_type',
'period', 'qualifiers', 'satisfied_events_types', 'second', 'team_id',
'type', 'x', 'y', 'end_x', 'end_y', 'player_id', 'blocked_x',
'blocked_y', 'goal_mouth_y', 'goal_mouth_z', 'is_shot',
'related_event_id', 'related_player_id', 'is_goal', 'card_type', '$idx',
'$len', 'field', 'minute_info', 'satisfiers', 'text', 'game_id',
'player', 'team']
for col in cols:
if col not in df.columns:
df[col] = np.nan
PS: It exists a similar issue with feature 'card_type' if no card were given during the game.
Thanks,
Ben
The text was updated successfully, but these errors were encountered: