Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

Commit

Permalink
Implemented goalkeeper_info
Browse files Browse the repository at this point in the history
  • Loading branch information
ElSaico committed Oct 3, 2018
1 parent 834a1ca commit 5da1800
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pystatsbomb/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from pandas.io.json import json_normalize


def all_clean(df):
Expand Down Expand Up @@ -26,7 +27,20 @@ def clean_locations(df):


def goalkeeper_info(df):
raise NotImplementedError
def get_goalkeeper(ff):
dff = json_normalize(ff)
filtered = dff[~dff.teammate & (dff['position.name'] == 'Goalkeeper')]
if filtered.empty:
filtered = filtered.append({}, ignore_index=True)
return filtered.iloc[0]

goalkeepers = df['shot.freeze_frame'].dropna().apply(get_goalkeeper)
return df.assign(**{
'player.id.GK': goalkeepers['player.id'],
'player.name.GK': goalkeepers['player.name'],
'location.x.GK': goalkeepers.location.map(lambda gk: gk[0], na_action='ignore'),
'location.y.GK': goalkeepers.location.map(lambda gk: gk[1], na_action='ignore'),
})


def shot_info(df):
Expand Down

0 comments on commit 5da1800

Please sign in to comment.