본문 바로가기

Minding's Baseball/MLB Statcast

[MLB Stats API] statsapi.player_stats(personId, group="[hitting,pitching,fielding]", type="season")

728x90
반응형

[MLB Stats API] 파이썬 패키지로 MLB Stats API 사용해보기

 

[MLB Stats API] 파이썬 패키지로 MLB Stats API 사용해보기

Fangraph나 MLB savant 홈페이지에서 직접 csv, DB파일을 다운로드 받는 것이 아닌 MLB서버에 연결된 API로 손쉽게 데이터를 구할 수 있는 방법을 야구공작소 글을 보며 알게되었다. 그 중 파이썬으로 API

minding-deep-learning.tistory.com


  • 선수의 현재 시즌기록 또는 통산기록을 출력 (선수Id 필요)
  • group 파라미터에는 문자열로 입력 / 여러 그룹을 포함하려면 "[]" 형식으로 입력
  • type 파라미터로 통산기록 / 현재시즌 기록 따로 또는 다 같이 출력 가능 ('career', 'season', '[career,season]')
# 추신수 선수의 통산 타격기록
# get함수를 통해 선수id 조회 (season은 그 선수가 활동한 아무때나)
print( statsapi.player_stats(next(x['id'] for x in statsapi.get('sports_players',{'season':2008,'gameType':'W'})['people'] if x['fullName']=='Shin-Soo Choo'), 'hitting', 'career') )
Shin-Soo "Korean Kid" Choo, LF (2005-)

Career Hitting
gamesPlayed: 1652
groundOuts: 1677
airOuts: 1210
runs: 961
doubles: 339
triples: 29
homeRuns: 218
strikeOuts: 1579
baseOnBalls: 868
intentionalWalks: 43
hits: 1671
hitByPitch: 152
avg: .275
atBats: 6087
obp: .377
slg: .447
ops: .824
caughtStealing: 55
stolenBases: 157
stolenBasePercentage: .741
groundIntoDoublePlay: 101
numberOfPitches: 28975
plateAppearances: 7157
totalBases: 2722
rbi: 782
leftOnBase: 2196
sacBunts: 10
sacFlies: 40
babip: .336
groundOutsToAirouts: 1.39
catchersInterference: 0
atBatsPerHomeRun: 27.92

 

# 류현진 선수의 MLB 통산기록 출력

print( statsapi.player_stats(next(x['id'] for x in statsapi.get('sports_players',{'season':2019,'gameType':'W'})['people'] if x['fullName']=='Hyun Jin Ryu'), 'pitching', 'career') )
Hyun Jin "Monster" Ryu, P (2013-)

Career Pitching
gamesPlayed: 169
gamesStarted: 168
groundOuts: 1138
airOuts: 822
runs: 374
doubles: 192
triples: 12
homeRuns: 102
strikeOuts: 880
baseOnBalls: 218
intentionalWalks: 13
hits: 928
hitByPitch: 16
avg: .249
atBats: 3729
obp: .292
slg: .389
ops: .681
caughtStealing: 7
stolenBases: 8
stolenBasePercentage: .533
groundIntoDoublePlay: 96
numberOfPitches: 15495
era: 3.20
inningsPitched: 976.1
wins: 73
losses: 45
saves: 1
saveOpportunities: 1
holds: 0
blownSaves: 0
earnedRuns: 347
whip: 1.17
battersFaced: 4002
outs: 2929
gamesPitched: 169
completeGames: 4
shutouts: 3
strikes: 10087
strikePercentage: .650
hitBatsmen: 16
balks: 1
wildPitches: 14
pickoffs: 5
totalBases: 1450
groundOutsToAirouts: 1.38
winPercentage: .619
pitchesPerInning: 15.87
gamesFinished: 1
strikeoutWalkRatio: 4.04
strikeoutsPer9Inn: 8.11
walksPer9Inn: 2.01
hitsPer9Inn: 8.55
runsScoredPer9: 3.45
homeRunsPer9: 0.94
inheritedRunners: 0
inheritedRunnersScored: 0
catchersInterference: 0
sacBunts: 28
sacFlies: 11
728x90