Understat#

[1]:
import sys

sys.path.append("../../")

import penaltyblog as pb

List available competitions#

[2]:
pb.scrapers.Understat.list_competitions()
[2]:
['DEU Bundesliga 1',
 'ENG Premier League',
 'ESP La Liga',
 'FRA Ligue 1',
 'ITA Serie A',
 'RUS Premier League']

Get Fixtures#

[3]:
under = pb.scrapers.Understat("ENG Premier League", "2021-2022")
df = under.get_fixtures()
df.head()
[3]:
understat_id datetime team_home team_away goals_home goals_away xg_home xg_away forecast_w forecast_d forecast_l season competition date
id
1628812800---brentford---arsenal 16376 2021-08-13 19:00:00 Brentford Arsenal 2 0 1.888180 1.023850 0.6289 0.2287 0.1424 2021-2022 ENG Premier League 2021-08-13
1628899200---burnley---brighton 16378 2021-08-14 14:00:00 Burnley Brighton 1 2 1.795480 1.685300 0.3894 0.2877 0.3229 2021-2022 ENG Premier League 2021-08-14
1628899200---chelsea---crystal_palace 16379 2021-08-14 14:00:00 Chelsea Crystal Palace 3 0 1.187090 0.321701 0.6405 0.2822 0.0773 2021-2022 ENG Premier League 2021-08-14
1628899200---everton---southampton 16380 2021-08-14 14:00:00 Everton Southampton 3 1 2.388630 0.580601 0.8359 0.1234 0.0407 2021-2022 ENG Premier League 2021-08-14
1628899200---leicester---wolverhampton_wanderers 16381 2021-08-14 14:00:00 Leicester Wolverhampton Wanderers 1 0 0.668082 1.327140 0.1683 0.2750 0.5567 2021-2022 ENG Premier League 2021-08-14

Get shots from a specific match (using the understat_id from the fixtures)#

[4]:
shots = under.get_shots("16380")
shots.head()
[4]:
competition season datetime minute result x y x_g player h_a ... situation shot_type match_id team_home team_away goals_home goals_away date player_assisted last_action
id
1628899200---everton---southampton ENG Premier League 2021-2022 2021-08-14 14:00:00 2 SavedShot 0.8059999847412109 0.37099998474121093 0.03489129990339279 Allan h ... OpenPlay RightFoot 16380 Everton Southampton 3 1 2021-08-14 None None
1628899200---everton---southampton ENG Premier League 2021-2022 2021-08-14 14:00:00 9 MissedShots 0.9580000305175781 0.45799999237060546 0.11126399785280228 Dominic Calvert-Lewin h ... OpenPlay Head 16380 Everton Southampton 3 1 2021-08-14 Demarai Gray Aerial
1628899200---everton---southampton ENG Premier League 2021-2022 2021-08-14 14:00:00 33 BlockedShot 0.784000015258789 0.40900001525878904 0.08816669881343842 Lucas Digne h ... DirectFreekick LeftFoot 16380 Everton Southampton 3 1 2021-08-14 None Standard
1628899200---everton---southampton ENG Premier League 2021-2022 2021-08-14 14:00:00 34 MissedShots 0.9409999847412109 0.5270000076293946 0.09325270354747772 Dominic Calvert-Lewin h ... OpenPlay Head 16380 Everton Southampton 3 1 2021-08-14 Andros Townsend Cross
1628899200---everton---southampton ENG Premier League 2021-2022 2021-08-14 14:00:00 43 MissedShots 0.774000015258789 0.645 0.01725040003657341 Lucas Digne h ... FromCorner LeftFoot 16380 Everton Southampton 3 1 2021-08-14 None None

5 rows × 21 columns

Get the other stats for the fixture#

[5]:
info = under.get_fixture_info("16380")

info
[5]:
competition season datetime fid h a date league_id goals_home goals_away ... h_l league shots_home shots_away shots_on_target_home shots_on_target_away deep_home deep_away ppda_away ppda_home
id
1628899200---everton---southampton ENG Premier League 2021-2022 2021-08-14 14:00:00 1549542 72 74 2021-08-14 1 3 1 ... 0.0407 EPL 14 6 6 3 4 6 5.5926 6.8696

1 rows × 26 columns

Get the season for Erling Haaland#

[6]:
player = under.get_player_season(8260)
player
[6]:
team position games goals shots time x_g assists x_a key_passes yellow red npg npx_g x_g_chain x_g_buildup
season
2019 Borussia Dortmund Sub 15 13 33 1061 8.889357395470142 2 1.5264755114912987 9 0 0 13 8.889357395470142 11.366187927313149 2.984985080547631
2020 Borussia Dortmund FW 28 27 92 2416 23.59848389774561 6 4.03544756770134 27 2 0 25 20.567368783056736 27.197287127375603 5.896189399063587
2021 Borussia Dortmund FW 24 22 80 1917 17.030953601002693 7 5.894002065062523 23 3 0 16 12.484372556209564 19.77244157716632 4.264734441414475
2022 Manchester City FW 35 36 123 2803 32.761399537324905 8 5.8491098545491695 29 5 0 29 27.433209866285324 31.963398084044456 3.285816218703985
2023 Manchester City FW 31 27 122 2581 31.65399668365717 5 4.7517555598169565 29 1 0 20 25.564646281301975 30.19725350290537 3.128645434975624
2024 Manchester City FW 15 13 70 1350 14.533826172351837 1 1.5637084767222404 11 2 0 12 13.772657334804535 12.936081945896149 1.5715587697923183

Get all Erling Haaland’s shots#

[7]:
shots = under.get_player_shots(8260)
shots
[7]:
minute result x y x_g player h_a understat_player_id situation season ... understat_fixture_id team_home team_away goals_home goals_away date player_assisted last_action datetime id
understat_shot_id
354876 58 Goal 0.8880000305175781 0.6659999847412109 0.07933320105075836 Erling Haaland a 8260 OpenPlay 2019 ... 12562 Augsburg Borussia Dortmund 3 5 2020-01-18 Jadon Sancho Throughball 2020-01-18 14:30:00 1579305600---augsburg---borussia_dortmund
354881 69 Goal 0.98 0.48900001525878906 0.9206209778785706 Erling Haaland a 8260 OpenPlay 2019 ... 12562 Augsburg Borussia Dortmund 3 5 2020-01-18 Thorgan Hazard Pass 2020-01-18 14:30:00 1579305600---augsburg---borussia_dortmund
354883 78 Goal 0.8830000305175781 0.34700000762939454 0.32283100485801697 Erling Haaland a 8260 OpenPlay 2019 ... 12562 Augsburg Borussia Dortmund 3 5 2020-01-18 Marco Reus Throughball 2020-01-18 14:30:00 1579305600---augsburg---borussia_dortmund
355527 65 BlockedShot 0.8859999847412109 0.639000015258789 0.11918099969625473 Erling Haaland h 8260 OpenPlay 2019 ... 12566 Borussia Dortmund FC Cologne 5 1 2020-01-24 Jadon Sancho Pass 2020-01-24 19:30:00 1579824000---borussia_dortmund---fc_cologne
355531 76 Goal 0.955 0.495 0.7466409802436829 Erling Haaland h 8260 OpenPlay 2019 ... 12566 Borussia Dortmund FC Cologne 5 1 2020-01-24 None Rebound 2020-01-24 19:30:00 1579824000---borussia_dortmund---fc_cologne
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
605209 5 SavedShot 0.8630000305175781 0.4929999923706055 0.07168060541152954 Erling Haaland h 8260 OpenPlay 2024 ... 26739 Manchester City Nottingham Forest 3 0 2024-12-04 Kevin De Bruyne Cross 2024-12-04 19:30:00 1733270400---manchester_city---nottingham_forest
605236 91 MissedShots 0.8209999847412109 0.700999984741211 0.2730585038661957 Erling Haaland h 8260 OpenPlay 2024 ... 26739 Manchester City Nottingham Forest 3 0 2024-12-04 None None 2024-12-04 19:30:00 1733270400---manchester_city---nottingham_forest
605849 6 SavedShot 0.89 0.5229999923706055 0.43306636810302734 Erling Haaland a 8260 OpenPlay 2024 ... 26747 Crystal Palace Manchester City 2 2 2024-12-07 Kevin De Bruyne Throughball 2024-12-07 15:00:00 1733529600---crystal_palace---manchester_city
605857 29 Goal 0.9290000152587891 0.46 0.2861519753932953 Erling Haaland a 8260 OpenPlay 2024 ... 26747 Crystal Palace Manchester City 2 2 2024-12-07 Matheus Nunes Aerial 2024-12-07 15:00:00 1733529600---crystal_palace---manchester_city
605868 74 BlockedShot 0.965 0.44 0.06939429044723511 Erling Haaland a 8260 FromCorner 2024 ... 26747 Crystal Palace Manchester City 2 2 2024-12-07 Matheus Nunes Aerial 2024-12-07 15:00:00 1733529600---crystal_palace---manchester_city

520 rows × 21 columns