작성일자 : 2023-08-27
Ver 0.1.1
Ver 0.1.1
- 데이터 불러오기
- pandas.read_csv: https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html
- pandas.read_pickle: https://pandas.pydata.org/docs/reference/api/pandas.read_pickle.html
- 중복 제거를 활용한 데이터 구성 파악
- pandas.Series.unique: https://pandas.pydata.org/docs/reference/api/pandas.Series.unique.html
- pandas.DataFrame.drop_duplicates: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.drop_duplicates.html
- pandas.DataFrame.sort_values: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_values.html
- set: https://wikidocs.net/22262
데이터 불러오기¶
In [1]:
import pandas as pd, os
In [2]:
os.getcwd()
Out[2]:
'/Users/limjongjun/Desktop/JayJay/Growth/Python/soccer-analytics/Excercise'
In [3]:
# directory 변경
new_dir = '/Users/limjongjun/Desktop/JayJay/Growth/Python/soccer-analytics'
os.chdir(new_dir)
os.getcwd()
Out[3]:
'/Users/limjongjun/Desktop/JayJay/Growth/Python/soccer-analytics'
(1) 경기 정보 불러오기¶
In [5]:
dataset_name = 'England'
match_df = pd.read_csv(f'data/refined_events/{dataset_name}/matches.csv', index_col=0, encoding='utf-8-sig') #pkl 파일들 가장 밑에 csv 파일 존재
match_df
Out[5]:
gameweek | datetime | venue | team1_id | team1_name | team1_goals | team2_id | team2_name | team2_goals | duration | |
---|---|---|---|---|---|---|---|---|---|---|
match_id | ||||||||||
2499719 | 1 | 2017-08-11 18:45:00 | Emirates Stadium | 1609 | Arsenal | 4 | 1631 | Leicester City | 3 | Regular |
2499727 | 1 | 2017-08-12 11:30:00 | Vicarage Road Stadium | 1644 | Watford | 3 | 1612 | Liverpool | 3 | Regular |
2499726 | 1 | 2017-08-12 14:00:00 | St. Mary's Stadium | 1619 | Southampton | 0 | 10531 | Swansea City | 0 | Regular |
2499721 | 1 | 2017-08-12 14:00:00 | Stamford Bridge | 1610 | Chelsea | 2 | 1646 | Burnley | 3 | Regular |
2499728 | 1 | 2017-08-12 14:00:00 | The Hawthorns | 1627 | West Bromwich Albion | 1 | 1659 | AFC Bournemouth | 0 | Regular |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2500092 | 38 | 2018-05-13 14:00:00 | Anfield | 1612 | Liverpool | 4 | 1651 | Brighton & Hove Albion | 0 | Regular |
2500091 | 38 | 2018-05-13 14:00:00 | The John Smith's Stadium | 1673 | Huddersfield Town | 0 | 1609 | Arsenal | 1 | Regular |
2500090 | 38 | 2018-05-13 14:00:00 | Selhurst Park | 1628 | Crystal Palace | 2 | 1627 | West Bromwich Albion | 0 | Regular |
2500098 | 38 | 2018-05-13 14:00:00 | London Stadium | 1633 | West Ham United | 3 | 1623 | Everton | 1 | Regular |
2500089 | 38 | 2018-05-13 14:00:00 | Turf Moor | 1646 | Burnley | 1 | 1659 | AFC Bournemouth | 2 | Regular |
380 rows × 10 columns
(2) 경기 정보 필터링¶
In [6]:
match_df[(match_df['team1_name'] == 'Manchester City') | (match_df['team2_name'] == 'Manchester City')] #Index
Out[6]:
gameweek | datetime | venue | team1_id | team1_name | team1_goals | team2_id | team2_name | team2_goals | duration | |
---|---|---|---|---|---|---|---|---|---|---|
match_id | ||||||||||
2499720 | 1 | 2017-08-12 16:30:00 | The American Express Community Stadium | 1651 | Brighton & Hove Albion | 0 | 1625 | Manchester City | 2 | Regular |
2499734 | 2 | 2017-08-21 19:00:00 | Etihad Stadium | 1625 | Manchester City | 1 | 1623 | Everton | 1 | Regular |
2499739 | 3 | 2017-08-26 11:30:00 | Vitality Stadium | 1659 | AFC Bournemouth | 1 | 1625 | Manchester City | 2 | Regular |
2499754 | 4 | 2017-09-09 11:30:00 | Etihad Stadium | 1625 | Manchester City | 5 | 1612 | Liverpool | 0 | Regular |
2499767 | 5 | 2017-09-16 14:00:00 | Vicarage Road Stadium | 1644 | Watford | 0 | 1625 | Manchester City | 6 | Regular |
2499774 | 6 | 2017-09-23 14:00:00 | Etihad Stadium | 1625 | Manchester City | 5 | 1628 | Crystal Palace | 0 | Regular |
2499781 | 7 | 2017-09-30 16:30:00 | Stamford Bridge | 1610 | Chelsea | 0 | 1625 | Manchester City | 1 | Regular |
2499794 | 8 | 2017-10-14 14:00:00 | Etihad Stadium | 1625 | Manchester City | 7 | 1639 | Stoke City | 2 | Regular |
2499802 | 9 | 2017-10-21 14:00:00 | Etihad Stadium | 1625 | Manchester City | 3 | 1646 | Burnley | 0 | Regular |
2499818 | 10 | 2017-10-28 14:00:00 | The Hawthorns | 1627 | West Bromwich Albion | 2 | 1625 | Manchester City | 3 | Regular |
2499822 | 11 | 2017-11-05 14:15:00 | Etihad Stadium | 1625 | Manchester City | 3 | 1609 | Arsenal | 1 | Regular |
2499834 | 12 | 2017-11-18 15:00:00 | King Power Stadium | 1631 | Leicester City | 0 | 1625 | Manchester City | 2 | Regular |
2499841 | 13 | 2017-11-26 16:00:00 | The John Smith's Stadium | 1673 | Huddersfield Town | 1 | 1625 | Manchester City | 2 | Regular |
2499857 | 14 | 2017-11-29 20:00:00 | Etihad Stadium | 1625 | Manchester City | 2 | 1619 | Southampton | 1 | Regular |
2499865 | 15 | 2017-12-03 16:00:00 | Etihad Stadium | 1625 | Manchester City | 2 | 1633 | West Ham United | 1 | Regular |
2499873 | 16 | 2017-12-10 16:30:00 | Old Trafford | 1611 | Manchester United | 1 | 1625 | Manchester City | 2 | Regular |
2499881 | 17 | 2017-12-13 19:45:00 | Liberty Stadium | 10531 | Swansea City | 0 | 1625 | Manchester City | 4 | Regular |
2499895 | 18 | 2017-12-16 17:30:00 | Etihad Stadium | 1625 | Manchester City | 4 | 1624 | Tottenham Hotspur | 1 | Regular |
2499904 | 19 | 2017-12-23 15:00:00 | Etihad Stadium | 1625 | Manchester City | 4 | 1659 | AFC Bournemouth | 0 | Regular |
2499915 | 20 | 2017-12-27 19:45:00 | St. James' Park | 1613 | Newcastle United | 0 | 1625 | Manchester City | 1 | Regular |
2499921 | 21 | 2017-12-31 12:00:00 | Selhurst Park | 1628 | Crystal Palace | 0 | 1625 | Manchester City | 0 | Regular |
2499934 | 22 | 2018-01-02 20:00:00 | Etihad Stadium | 1625 | Manchester City | 3 | 1644 | Watford | 1 | Regular |
2499943 | 23 | 2018-01-14 16:00:00 | Anfield | 1612 | Liverpool | 4 | 1625 | Manchester City | 3 | Regular |
2499954 | 24 | 2018-01-20 17:30:00 | Etihad Stadium | 1625 | Manchester City | 3 | 1613 | Newcastle United | 1 | Regular |
2499966 | 25 | 2018-01-31 20:00:00 | Etihad Stadium | 1625 | Manchester City | 3 | 1627 | West Bromwich Albion | 0 | Regular |
2499972 | 26 | 2018-02-03 12:30:00 | Turf Moor | 1646 | Burnley | 1 | 1625 | Manchester City | 1 | Regular |
2499982 | 27 | 2018-02-10 17:30:00 | Etihad Stadium | 1625 | Manchester City | 5 | 1631 | Leicester City | 1 | Regular |
2499990 | 28 | 2018-03-01 19:45:00 | Emirates Stadium | 1609 | Arsenal | 0 | 1625 | Manchester City | 3 | Regular |
2500004 | 29 | 2018-03-04 16:00:00 | Etihad Stadium | 1625 | Manchester City | 1 | 1610 | Chelsea | 0 | Regular |
2500016 | 30 | 2018-03-12 20:00:00 | Bet365 Stadium | 1639 | Stoke City | 0 | 1625 | Manchester City | 2 | Regular |
2500033 | 32 | 2018-03-31 16:30:00 | Goodison Park | 1623 | Everton | 1 | 1625 | Manchester City | 3 | Regular |
2500045 | 33 | 2018-04-07 16:30:00 | Etihad Stadium | 1625 | Manchester City | 2 | 1611 | Manchester United | 3 | Regular |
2500057 | 34 | 2018-04-14 18:45:00 | Wembley Stadium | 1624 | Tottenham Hotspur | 1 | 1625 | Manchester City | 3 | Regular |
2500065 | 35 | 2018-04-22 15:30:00 | Etihad Stadium | 1625 | Manchester City | 5 | 10531 | Swansea City | 0 | Regular |
2500078 | 36 | 2018-04-29 13:15:00 | London Stadium | 1633 | West Ham United | 1 | 1625 | Manchester City | 4 | Regular |
2500085 | 37 | 2018-05-06 12:30:00 | Etihad Stadium | 1625 | Manchester City | 0 | 1673 | Huddersfield Town | 0 | Regular |
2500024 | 31 | 2018-05-09 19:00:00 | Etihad Stadium | 1625 | Manchester City | 3 | 1651 | Brighton & Hove Albion | 1 | Regular |
2500095 | 38 | 2018-05-13 14:00:00 | St. Mary's Stadium | 1619 | Southampton | 0 | 1625 | Manchester City | 1 | Regular |
(3) 경기 이벤트 데이터 불러오기¶
- 17/18 시즌 18Round Mancity vs Tottenham
In [7]:
match_id = 2499895
match_events = pd.read_pickle(f'data/refined_events/{dataset_name}/{match_id}.pkl') #pkl 파일을 Dataframe으로 불러오기
match_events
Out[7]:
match_id | event_id | period | time | team_id | team_name | player_id | player_name | event_type | sub_event_type | tags | start_x | start_y | end_x | end_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2499895 | 215108367 | 1H | 1.784 | 1625 | Manchester City | 8325 | S. Agüero | Pass | Simple pass | [Accurate] | 52.00 | 34.68 | 40.56 | 34.68 |
1 | 2499895 | 215108368 | 1H | 3.324 | 1625 | Manchester City | 105339 | Fernandinho | Pass | Simple pass | [Accurate] | 40.56 | 34.68 | 29.12 | 8.16 |
2 | 2499895 | 215108369 | 1H | 6.406 | 1625 | Manchester City | 8277 | K. Walker | Pass | Simple pass | [Accurate] | 29.12 | 8.16 | 44.72 | 10.20 |
3 | 2499895 | 215108370 | 1H | 7.124 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 44.72 | 10.20 | 69.68 | 6.12 |
4 | 2499895 | 215108371 | 1H | 8.676 | 1625 | Manchester City | 11066 | R. Sterling | Pass | Simple pass | [Accurate] | 69.68 | 6.12 | 58.24 | 12.24 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
1607 | 2499895 | 215110122 | 2H | 2875.703 | 1624 | Tottenham Hotspur | 210044 | E. Dier | Pass | Simple pass | [Accurate] | 36.40 | 26.52 | 48.88 | 29.92 |
1608 | 2499895 | 215110123 | 2H | 2876.142 | 1624 | Tottenham Hotspur | 240070 | H. Winks | Duel | Ground attacking duel | [Anticipation, Lost, Not accurate] | 48.88 | 29.92 | 43.68 | 24.48 |
1609 | 2499895 | 215109959 | 2H | 2876.768 | 1625 | Manchester City | 447205 | P. Foden | Duel | Ground defending duel | [Anticipated, Won, Accurate] | 55.12 | 38.08 | 60.32 | 43.52 |
1610 | 2499895 | 215109960 | 2H | 2878.046 | 1625 | Manchester City | 11066 | R. Sterling | Duel | Ground attacking duel | [Free space right, Lost, Not accurate] | 60.32 | 43.52 | 60.32 | 43.52 |
1611 | 2499895 | 215110124 | 2H | 2878.216 | 1624 | Tottenham Hotspur | 240070 | H. Winks | Duel | Ground defending duel | [Free space left, Lost, Not accurate] | 43.68 | 24.48 | NaN | NaN |
1612 rows × 15 columns
이벤트 데이터 인덱싱(indexing), 슬라이싱(slicing), 필터링(filtering)¶
(1) 열 인덱싱(column indexing)¶
In [8]:
match_events['player_name']
Out[8]:
0 S. Agüero 1 Fernandinho 2 K. Walker 3 K. De Bruyne 4 R. Sterling ... 1607 E. Dier 1608 H. Winks 1609 P. Foden 1610 R. Sterling 1611 H. Winks Name: player_name, Length: 1612, dtype: object
(2) 행 인덱싱(row indexing)¶
In [9]:
match_events.loc[0]
Out[9]:
match_id 2499895 event_id 215108367 period 1H time 1.784 team_id 1625 team_name Manchester City player_id 8325 player_name S. Agüero event_type Pass sub_event_type Simple pass tags [Accurate] start_x 52.0 start_y 34.68 end_x 40.56 end_y 34.68 Name: 0, dtype: object
(3) 슬라이싱¶
In [10]:
match_events[0:10]
Out[10]:
match_id | event_id | period | time | team_id | team_name | player_id | player_name | event_type | sub_event_type | tags | start_x | start_y | end_x | end_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2499895 | 215108367 | 1H | 1.784 | 1625 | Manchester City | 8325 | S. Agüero | Pass | Simple pass | [Accurate] | 52.00 | 34.68 | 40.56 | 34.68 |
1 | 2499895 | 215108368 | 1H | 3.324 | 1625 | Manchester City | 105339 | Fernandinho | Pass | Simple pass | [Accurate] | 40.56 | 34.68 | 29.12 | 8.16 |
2 | 2499895 | 215108369 | 1H | 6.406 | 1625 | Manchester City | 8277 | K. Walker | Pass | Simple pass | [Accurate] | 29.12 | 8.16 | 44.72 | 10.20 |
3 | 2499895 | 215108370 | 1H | 7.124 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 44.72 | 10.20 | 69.68 | 6.12 |
4 | 2499895 | 215108371 | 1H | 8.676 | 1625 | Manchester City | 11066 | R. Sterling | Pass | Simple pass | [Accurate] | 69.68 | 6.12 | 58.24 | 12.24 |
5 | 2499895 | 215108382 | 1H | 9.282 | 1624 | Tottenham Hotspur | 240070 | H. Winks | Duel | Ground loose ball duel | [Won, Accurate] | 45.76 | 55.76 | 47.84 | 61.20 |
6 | 2499895 | 215108372 | 1H | 9.415 | 1625 | Manchester City | 38021 | K. De Bruyne | Duel | Ground loose ball duel | [Lost, Not accurate] | 58.24 | 12.24 | 56.16 | 6.80 |
7 | 2499895 | 215108383 | 1H | 11.223 | 1624 | Tottenham Hotspur | 8292 | D. Rose | Pass | Simple pass | [Not accurate] | 47.84 | 61.20 | 55.12 | 47.60 |
8 | 2499895 | 215108373 | 1H | 12.536 | 1625 | Manchester City | 38021 | K. De Bruyne | Others on the ball | Touch | [Interception] | 48.88 | 20.40 | 49.92 | 0.00 |
9 | 2499895 | 215108384 | 1H | 15.649 | 1624 | Tottenham Hotspur | 0 | NaN | Interruption | Ball out of the field | [] | 54.08 | 68.00 | NaN | NaN |
(4) 필터링 또는 불린 인덱싱(Boolean indexing)¶
In [11]:
match_events[match_events['event_type'] == 'Shot'].head() #Shooting에 대한 Action만 필터링
Out[11]:
match_id | event_id | period | time | team_id | team_name | player_id | player_name | event_type | sub_event_type | tags | start_x | start_y | end_x | end_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
204 | 2499895 | 215108558 | 1H | 549.772 | 1625 | Manchester City | 8325 | S. Agüero | Shot | Shot | [Head/body, Opportunity, Position: Out low rig... | 95.68 | 25.84 | 104.0 | 34.0 |
299 | 2499895 | 215108640 | 1H | 822.817 | 1625 | Manchester City | 14808 | İ. Gündoğan | Shot | Shot | [Goal, Head/body, Opportunity, Position: Goal ... | 95.68 | 38.76 | 104.0 | 34.0 |
452 | 2499895 | 215108755 | 1H | 1380.188 | 1625 | Manchester City | 8325 | S. Agüero | Shot | Shot | [Left foot, Opportunity, Position: Goal low ce... | 88.40 | 49.64 | 104.0 | 34.0 |
456 | 2499895 | 215108760 | 1H | 1385.615 | 1625 | Manchester City | 11066 | R. Sterling | Shot | Shot | [Left foot, Opportunity, Position: Out high le... | 91.52 | 42.84 | 104.0 | 34.0 |
480 | 2499895 | 215108786 | 1H | 1474.472 | 1625 | Manchester City | 38021 | K. De Bruyne | Shot | Shot | [Left foot, Opportunity, Position: Goal low le... | 80.08 | 36.72 | 104.0 | 34.0 |
In [12]:
match_events[match_events['player_name'] == 'K. De Bruyne'].tail(6)
Out[12]:
match_id | event_id | period | time | team_id | team_name | player_id | player_name | event_type | sub_event_type | tags | start_x | start_y | end_x | end_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1498 | 2499895 | 215109844 | 2H | 2448.209 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 73.84 | 60.52 | 80.08 | 62.56 |
1502 | 2499895 | 215109848 | 2H | 2455.843 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 67.60 | 61.20 | 85.28 | 64.60 |
1513 | 2499895 | 215109860 | 2H | 2483.958 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 71.76 | 18.36 | 93.60 | 13.60 |
1516 | 2499895 | 215109864 | 2H | 2489.462 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 83.20 | 18.36 | 94.64 | 15.64 |
1536 | 2499895 | 215109885 | 2H | 2522.511 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 73.84 | 8.16 | 81.12 | 36.72 |
1549 | 2499895 | 215109899 | 2H | 2577.333 | 1625 | Manchester City | 38021 | K. De Bruyne | Pass | Simple pass | [Accurate] | 44.72 | 18.36 | 29.12 | 26.52 |
중복 제거를 활용한 데이터 구성 파악¶
(1) Series 원소 중복 제거¶
- 전후반 구분
In [13]:
match_events['period'].unique() #Unique 값으로 변환
Out[13]:
array(['1H', '2H'], dtype=object)
- 팀 구분
In [14]:
match_events['team_name'].unique()
Out[14]:
array(['Manchester City', 'Tottenham Hotspur'], dtype=object)
- 경기 출전 선수
In [15]:
match_events['player_name'].unique()
Out[15]:
array(['S. Agüero', 'Fernandinho', 'K. Walker', 'K. De Bruyne', 'R. Sterling', 'H. Winks', 'D. Rose', nan, 'H. Kane', 'N. Otamendi', 'M. Dembélé', 'E. Dier', 'H. Lloris', 'J. Vertonghen', 'F. Delph', 'Ederson', 'K. Trippier', 'Son Heung-Min', 'C. Eriksen', 'L. Sané', 'E. Mangala', 'İ. Gündoğan', 'D. Alli', 'Gabriel Jesus', 'E. Lamela', 'P. Foden', 'M. Sissoko', 'Bernardo Silva'], dtype=object)
(2) DataFrame 행 중복 제거¶
- 팀과 선수의 ID 및 이름
In [16]:
match_events[['team_id', 'team_name', 'player_id', 'player_name']].drop_duplicates() #이벤트 id 기준으로 정렬됨
Out[16]:
team_id | team_name | player_id | player_name | |
---|---|---|---|---|
0 | 1625 | Manchester City | 8325 | S. Agüero |
1 | 1625 | Manchester City | 105339 | Fernandinho |
2 | 1625 | Manchester City | 8277 | K. Walker |
3 | 1625 | Manchester City | 38021 | K. De Bruyne |
4 | 1625 | Manchester City | 11066 | R. Sterling |
5 | 1624 | Tottenham Hotspur | 240070 | H. Winks |
7 | 1624 | Tottenham Hotspur | 8292 | D. Rose |
9 | 1624 | Tottenham Hotspur | 0 | NaN |
12 | 1624 | Tottenham Hotspur | 8717 | H. Kane |
14 | 1625 | Manchester City | 70086 | N. Otamendi |
19 | 1624 | Tottenham Hotspur | 11152 | M. Dembélé |
20 | 1624 | Tottenham Hotspur | 210044 | E. Dier |
21 | 1624 | Tottenham Hotspur | 25381 | H. Lloris |
22 | 1624 | Tottenham Hotspur | 48 | J. Vertonghen |
33 | 1625 | Manchester City | 8464 | F. Delph |
35 | 1625 | Manchester City | 71654 | Ederson |
54 | 1624 | Tottenham Hotspur | 8945 | K. Trippier |
59 | 1624 | Tottenham Hotspur | 14911 | Son Heung-Min |
64 | 1624 | Tottenham Hotspur | 54 | C. Eriksen |
83 | 1625 | Manchester City | 245364 | L. Sané |
88 | 1625 | Manchester City | 70085 | E. Mangala |
89 | 1625 | Manchester City | 14808 | İ. Gündoğan |
107 | 1625 | Manchester City | 0 | NaN |
139 | 1624 | Tottenham Hotspur | 13484 | D. Alli |
1047 | 1625 | Manchester City | 340386 | Gabriel Jesus |
1362 | 1624 | Tottenham Hotspur | 20441 | E. Lamela |
1452 | 1625 | Manchester City | 447205 | P. Foden |
1457 | 1624 | Tottenham Hotspur | 25804 | M. Sissoko |
1476 | 1625 | Manchester City | 265673 | Bernardo Silva |
In [17]:
match_events[['team_id', 'team_name', 'player_id', 'player_name']].drop_duplicates().sort_values('team_id') #team_id 기준으로 정렬
Out[17]:
team_id | team_name | player_id | player_name | |
---|---|---|---|---|
59 | 1624 | Tottenham Hotspur | 14911 | Son Heung-Min |
1362 | 1624 | Tottenham Hotspur | 20441 | E. Lamela |
54 | 1624 | Tottenham Hotspur | 8945 | K. Trippier |
139 | 1624 | Tottenham Hotspur | 13484 | D. Alli |
5 | 1624 | Tottenham Hotspur | 240070 | H. Winks |
7 | 1624 | Tottenham Hotspur | 8292 | D. Rose |
9 | 1624 | Tottenham Hotspur | 0 | NaN |
12 | 1624 | Tottenham Hotspur | 8717 | H. Kane |
64 | 1624 | Tottenham Hotspur | 54 | C. Eriksen |
19 | 1624 | Tottenham Hotspur | 11152 | M. Dembélé |
20 | 1624 | Tottenham Hotspur | 210044 | E. Dier |
21 | 1624 | Tottenham Hotspur | 25381 | H. Lloris |
22 | 1624 | Tottenham Hotspur | 48 | J. Vertonghen |
1457 | 1624 | Tottenham Hotspur | 25804 | M. Sissoko |
0 | 1625 | Manchester City | 8325 | S. Agüero |
107 | 1625 | Manchester City | 0 | NaN |
1047 | 1625 | Manchester City | 340386 | Gabriel Jesus |
1452 | 1625 | Manchester City | 447205 | P. Foden |
89 | 1625 | Manchester City | 14808 | İ. Gündoğan |
88 | 1625 | Manchester City | 70085 | E. Mangala |
33 | 1625 | Manchester City | 8464 | F. Delph |
35 | 1625 | Manchester City | 71654 | Ederson |
14 | 1625 | Manchester City | 70086 | N. Otamendi |
4 | 1625 | Manchester City | 11066 | R. Sterling |
3 | 1625 | Manchester City | 38021 | K. De Bruyne |
2 | 1625 | Manchester City | 8277 | K. Walker |
1 | 1625 | Manchester City | 105339 | Fernandinho |
83 | 1625 | Manchester City | 245364 | L. Sané |
1476 | 1625 | Manchester City | 265673 | Bernardo Silva |
- 이벤트 유형의 종류
In [18]:
match_events[['event_type', 'sub_event_type']].drop_duplicates().sort_values(['event_type', 'sub_event_type'])
Out[18]:
event_type | sub_event_type | |
---|---|---|
16 | Duel | Air duel |
18 | Duel | Ground attacking duel |
19 | Duel | Ground defending duel |
5 | Duel | Ground loose ball duel |
34 | Foul | Foul |
650 | Foul | Hand foul |
298 | Free kick | Corner |
35 | Free kick | Free kick |
203 | Free kick | Free kick cross |
28 | Free kick | Goal kick |
1346 | Free kick | Penalty |
10 | Free kick | Throw in |
954 | Goalkeeper leaving line | Goalkeeper leaving line |
9 | Interruption | Ball out of the field |
555 | Interruption | Whistle |
214 | Offside | |
353 | Others on the ball | Acceleration |
113 | Others on the ball | Clearance |
8 | Others on the ball | Touch |
189 | Pass | Cross |
145 | Pass | Hand pass |
13 | Pass | Head pass |
15 | Pass | High pass |
313 | Pass | Launch |
0 | Pass | Simple pass |
160 | Pass | Smart pass |
300 | Save attempt | Reflexes |
481 | Save attempt | Save attempt |
204 | Shot | Shot |
1047 | Substitution | Player in |
1048 | Substitution | Player out |
(3) List 원소 중복 제거¶
- 추가 태그의 종류
In [19]:
match_events['tags'].sum() #리스트 형태로 변환
Out[19]:
['Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Not accurate', 'Interception', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Feint', 'Interception', 'Not accurate', 'Interception', 'Not accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Anticipation', 'Lost', 'Not accurate', 'Anticipated', 'Won', 'Accurate', 'Interception', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Not accurate', 'Not accurate', 'Interception', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Free space right', 'Lost', 'Not accurate', 'Free space left', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Missed ball', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Through', 'Not accurate', 'Interception', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Interception', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Sliding tackle', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Free space right', 'Lost', 'Not accurate', 'Free space left', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Anticipated', 'Won', 'Accurate', 'Anticipation', 'Neutral', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Through', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Anticipated', 'Won', 'Accurate', 'Anticipation', 'Lost', 'Not accurate', 'Accurate', 'Not accurate', 'Interception', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Through', 'Not accurate', 'Interception', 'Not accurate', 'Accurate', 'Not accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Left foot', 'Not accurate', 'Interception', 'Accurate', 'Not accurate', 'Accurate', 'Not accurate', 'Interception', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Free space left', 'Sliding tackle', 'Lost', 'Not accurate', 'Free space right', 'Won', 'Accurate', 'Key pass', 'High', 'Accurate', 'Head/body', 'Opportunity', 'Position: Out low right', 'Not accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Missed ball', 'Through', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Take on right', 'Won', 'Accurate', 'Take on left', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Free space left', 'Lost', 'Not accurate', 'Free space right', 'Won', 'Accurate', 'Right foot', 'Accurate', 'Interception', 'Accurate', 'Free space right', 'Won', 'Accurate', 'Free space left', 'Lost', 'Not accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Take on left', 'Lost', 'Not accurate', 'Take on right', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Free space right', 'Won', 'Accurate', 'Free space left', 'Lost', 'Not accurate', 'Accurate', 'Right foot', 'High', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Take on right', 'Lost', 'Not accurate', 'Take on left', 'Won', 'Accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Won', 'Accurate', 'Take on left', 'Lost', 'Not accurate', 'Not accurate', 'Assist', 'High', 'Accurate', 'Goal', 'Head/body', 'Opportunity', 'Position: Goal center left', 'Accurate', 'Position: Goal center left', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Through', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Not accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Free space left', 'Won', 'Accurate', 'Free space right', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Free space left', 'Lost', 'Not accurate', 'Free space right', 'Won', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Right foot', 'High', 'Not accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Free space right', 'Lost', 'Not accurate', 'Free space left', 'Won', 'Accurate', 'Left foot', 'Not accurate', 'Interception', 'Not accurate', 'High', 'Not accurate', 'Interception', 'Not accurate', 'Accurate', 'Accurate', 'Right foot', 'High', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Not accurate', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Through', 'Not accurate', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Through', 'Not accurate', 'Accurate', 'Key pass', 'Through', 'Accurate', 'Left foot', 'Opportunity', 'Position: Goal low center', 'Accurate', 'Position: Goal low center', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Left foot', 'Opportunity', 'Position: Out high left', 'Not accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Not accurate', 'Interception', 'Accurate', 'Feint', 'Not accurate', 'Interception', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Not accurate', 'Free space right', 'Lost', 'Not accurate', 'Free space left', 'Won', 'Accurate', 'Left foot', 'Opportunity', 'Position: Goal low left', 'Accurate', 'Position: Goal low left', 'Accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Not accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'High', 'Not accurate', 'Accurate', 'Take on right', 'Won', 'Accurate', 'Take on left', 'Lost', 'Not accurate', 'Counter attack', 'Accurate', 'Counter attack', 'Accurate', 'Counter attack', 'Accurate', 'Counter attack', 'Accurate', 'Counter attack', 'Accurate', 'Counter attack', 'Right foot', 'Opportunity', 'Position: Goal low center', 'Accurate', 'Position: Goal low center', 'Accurate', 'Accurate', 'Free space left', 'Lost', 'Not accurate', 'Free space right', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Free space left', 'Won', 'Accurate', 'Free space right', 'Lost', 'Not accurate', 'Take on left', 'Won', 'Accurate', 'Take on right', 'Lost', 'Not accurate', 'Take on left', 'Lost', 'Not accurate', 'Take on right', 'Won', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Dangerous ball lost', 'Not accurate', 'Interception', 'Accurate', 'Left foot', 'Accurate', 'Right foot', 'Blocked', 'Not accurate', 'Interception', 'Accurate', 'Anticipated', 'Won', 'Accurate', 'Anticipation', 'Lost', 'Not accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Not accurate', 'Fairplay', 'Not accurate', 'Fairplay', 'Not accurate', 'Accurate', 'Not accurate', 'Interception', 'Not accurate', 'Interception', 'Accurate', 'Not accurate', 'Interception', 'Free space right', 'Won', 'Accurate', 'Free space left', 'Lost', 'Not accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Counter attack', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Counter attack', 'Accurate', 'Counter attack', 'Counter attack', 'Free space left', 'Neutral', 'Accurate', 'Free space right', 'Neutral', 'Accurate', 'Counter attack', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Take on right', 'Lost', 'Not accurate', 'Take on left', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Missed ball', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Left foot', 'Opportunity', 'Position: Out low right', 'Not accurate', 'Not accurate', 'Interception', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Right foot', 'Opportunity', 'Position: Out low right', 'Not accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Accurate', 'Not accurate', 'Interception', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Yellow card', 'Not accurate', 'Interception', 'Not accurate', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Take on left', 'Neutral', 'Accurate', 'Take on right', 'Neutral', 'Accurate', 'Accurate', 'Not accurate', 'Accurate', 'Free space left', 'Won', 'Accurate', 'Free space right', 'Lost', 'Not accurate', 'Neutral', 'Accurate', 'Neutral', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'High', 'Not accurate', 'Interception', 'Not accurate', 'Right foot', 'Blocked', 'Not accurate', 'Interception', 'Accurate', 'Won', 'Accurate', 'Lost', 'Not accurate', 'Accurate', 'Accurate', 'Lost', 'Not accurate', 'Won', 'Accurate', 'Not accurate', 'Accurate', 'Accurate', 'Accurate', 'Accurate', ...]
In [20]:
set(match_events['tags'].sum())
Out[20]:
{13484, 14808, 14911, 20441, 245364, 25804, 265673, 340386, 447205, 8325, 'Accurate', 'Anticipated', 'Anticipation', 'Assist', 'Blocked', 'Counter attack', 'Dangerous ball lost', 'Fairplay', 'Feint', 'Free space left', 'Free space right', 'Goal', 'Head/body', 'High', 'Interception', 'Key pass', 'Left foot', 'Lost', 'Missed ball', 'Neutral', 'Not accurate', 'Opportunity', 'Position: Goal center', 'Position: Goal center left', 'Position: Goal center right', 'Position: Goal high left', 'Position: Goal low center', 'Position: Goal low left', 'Position: Goal low right', 'Position: Out high center', 'Position: Out high left', 'Position: Out high right', 'Position: Out low right', 'Position: Post low left', 'Right foot', 'Sliding tackle', 'Take on left', 'Take on right', 'Through', 'Won', 'Yellow card'}
In [21]:
match_events[match_events['event_type'] == 'Substitution'] #tags에 교체 대상 선수의 player id가 입력되어 있음
Out[21]:
match_id | event_id | period | time | team_id | team_name | player_id | player_name | event_type | sub_event_type | tags | start_x | start_y | end_x | end_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1047 | 2499895 | 0 | 2H | 660.0 | 1625 | Manchester City | 340386 | Gabriel Jesus | Substitution | Player in | [8325] | NaN | NaN | NaN | NaN |
1048 | 2499895 | 0 | 2H | 660.0 | 1625 | Manchester City | 8325 | S. Agüero | Substitution | Player out | [340386] | NaN | NaN | NaN | NaN |
1362 | 2499895 | 0 | 2H | 1860.0 | 1624 | Tottenham Hotspur | 20441 | E. Lamela | Substitution | Player in | [14911] | NaN | NaN | NaN | NaN |
1363 | 2499895 | 0 | 2H | 1860.0 | 1624 | Tottenham Hotspur | 14911 | Son Heung-Min | Substitution | Player out | [20441] | NaN | NaN | NaN | NaN |
1452 | 2499895 | 0 | 2H | 2220.0 | 1625 | Manchester City | 447205 | P. Foden | Substitution | Player in | [14808] | NaN | NaN | NaN | NaN |
1453 | 2499895 | 0 | 2H | 2220.0 | 1625 | Manchester City | 14808 | İ. Gündoğan | Substitution | Player out | [447205] | NaN | NaN | NaN | NaN |
1457 | 2499895 | 0 | 2H | 2280.0 | 1624 | Tottenham Hotspur | 25804 | M. Sissoko | Substitution | Player in | [13484] | NaN | NaN | NaN | NaN |
1458 | 2499895 | 0 | 2H | 2280.0 | 1624 | Tottenham Hotspur | 13484 | D. Alli | Substitution | Player out | [25804] | NaN | NaN | NaN | NaN |
1476 | 2499895 | 0 | 2H | 2340.0 | 1625 | Manchester City | 265673 | Bernardo Silva | Substitution | Player in | [245364] | NaN | NaN | NaN | NaN |
1477 | 2499895 | 0 | 2H | 2340.0 | 1625 | Manchester City | 245364 | L. Sané | Substitution | Player out | [265673] | NaN | NaN | NaN | NaN |