Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 코틀린
- 스프링
- Spring
- 안드로이드
- 자바스크립트
- oracle
- MLB
- kotlin
- Python
- CSS
- 판다스
- gcp
- 어플
- 앱
- 자바
- HTML
- 기록
- javascript
- 프로젝트
- 오라클
- 배포
- pandas
- Android
- streamlit
- 파이썬
- mlb stats api
- 제이쿼리
- JQuery
- 시간
- java
Archives
- Today
- Total
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 |