Notice
Recent Posts
Recent Comments
Link
250x250
develope_kkyu
[Python] MLB Stats API를 이용해 오타니, 저지 2022시즌 타격 성적 비교 본문
728x90
패키지 설치 및 임포트
!pip install MLB-StatsAPI
import statsapi
오타니와 저지 선수 id 검색
print(statsapi.lookup_player('ohtani'))
print(statsapi.lookup_player('judge'))
[{'id': 660271, 'fullName': 'Shohei Ohtani', 'firstName': 'Shohei', 'lastName': 'Ohtani', 'primaryNumber': '17', 'currentTeam': {'id': 108}, 'primaryPosition': {'code': 'Y', 'abbreviation': 'TWP'}, 'useName': 'Shohei', 'boxscoreName': 'Ohtani', 'nickName': 'Showtime', 'mlbDebutDate': '2018-03-29', 'nameFirstLast': 'Shohei Ohtani', 'firstLastName': 'Shohei Ohtani', 'lastFirstName': 'Ohtani, Shohei', 'lastInitName': 'Ohtani, S', 'initLastName': 'S Ohtani', 'fullFMLName': 'Shohei Ohtani', 'fullLFMName': 'Ohtani, Shohei'}]
[{'id': 592450, 'fullName': 'Aaron Judge', 'firstName': 'Aaron', 'lastName': 'Judge', 'primaryNumber': '99', 'currentTeam': {'id': 147}, 'primaryPosition': {'code': '9', 'abbreviation': 'RF'}, 'useName': 'Aaron', 'boxscoreName': 'Judge', 'nickName': 'Baj', 'mlbDebutDate': '2016-08-13', 'nameFirstLast': 'Aaron Judge', 'firstLastName': 'Aaron Judge', 'lastFirstName': 'Judge, Aaron', 'lastInitName': 'Judge, A', 'initLastName': 'A Judge', 'fullFMLName': 'Aaron James Judge', 'fullLFMName': 'Judge, Aaron James'}]
오타니, 저지 2022시즌 타격 성적 데이터프레임 만들기
import pandas as pd
ohtani = statsapi.player_stat_data(660271, group="[hitting]", type="season")['stats'][0]['stats']
judge = statsapi.player_stat_data(592450, group="[hitting]", type="season")['stats'][0]['stats']
sr_o = pd.Series(ohtani, name = 'Ohtani')
sr_j = pd.Series(judge, name = 'Judge')
df = pd.concat([sr_o,sr_j], axis = 1)
df
728x90
'Python' 카테고리의 다른 글
[Python] MLB Stats API를 이용해 내셔널리그 골든글러브 후보 3인 수비 지표 비교(김하성 포함) (0) | 2023.01.19 |
---|---|
[Python] plotly를 이용해 오타니, 저지 2022시즌 타격 성적 비교 그래프 (0) | 2023.01.19 |
[Python] pandas 예제 - 5 (0) | 2023.01.17 |
[Python] pandas 예제 - 4 (0) | 2023.01.05 |
[Python] pandas 예제 - 3 (0) | 2023.01.05 |