야구 분석/Python

놀란 아레나도 수비 지표 분석

sam_j_s 2024. 5. 15. 13:26
728x90
반응형

시각화 주제

메이저리그에서는 매년 최고의 수비수에게 주어지는 상이 있습니다. 골드 글러브 입니다. 골드 글러브는 선수의 수비만 평가에 들어갑니다.

 

선수 전체 기록을 보는 KBO의 골든 글러브와 다르게 메이저리그는 수비만 보는 골드 글러브와 공격만 보는 실버 슬러거로 나누어져 있고 투구에 대한 평가는 사이 영 상으로 나누어져 있습니다.

 

메이저리그 최고의 수비수 한테 주는 이 상을 10년 연속으로 받은 선수가 있습니다. 바로 놀란 아레나도 인데요. 아레나도는 데뷔시즌인 2013년부터 2023년까지 10년 연속으로 3루수 골드글러브를 수상했습니다. 그럼 공수겸장 현 최고 3루수 중 한명인 놀란 아레나도의 수비 지표를 확인해보겠습니다.

 

아레나도 무릎쏴 미친수비

 

 데이터 출처

메이저리그에서 제공하는 공식 API인 MLB Stats API를 이용하였습니다. 이 API를 통해 실시간 경기 결과, 선수 통계, 팀 정보, 시즌 데이터, 경기 일정 등 다양한 데이터를 가져올 수 있습니다.

 

데이터 분석

패키지 설치 및 임포트

필요한 패키지들을 설치하고 가져와주도록 하겠습니다.

import statsapi
import pandas as pd
import plotly.offline as pyo
import plotly.graph_objs as go

 

아레나도 데이터 불러오기

# 선수 이름으로 검색
search_results = statsapi.lookup_player('arenado')

# 검색 결과 출력
print(search_results)

 

아레나도의 id인 571448로 연도별 수비 지표를 가져오겠습니다.

 

arenado_stats = statsapi.player_stat_data(571448, group="[fielding]", type="yearByYear")
arenado_stats

10년의 지표가 나왔고 이것을 데이터 프레임으로 만들어 주겠습니다.

 

# 필요한 연도 데이터 필터링 및 데이터 프레임으로 변환
data = []
for year_data in arenado_stats['stats']:
    season = year_data['season']
    if 2013 <= int(season) <= 2023:
        stat_dict = {
            'Year': season,
            'Position': year_data['stats']['position']['abbreviation'],
            'Games Played': year_data['stats']['gamesPlayed'],
            'Games Started': year_data['stats']['gamesStarted'],
            'Innings': year_data['stats']['innings'],
            'Total Chances': year_data['stats']['chances'],
            'Put Outs': year_data['stats']['putOuts'],
            'Assists': year_data['stats']['assists'],
            'Errors': year_data['stats']['errors'],
            'Fielding Percentage': year_data['stats']['fielding'],
            'rangeFactorPerGame' : year_data['stats']['rangeFactorPerGame'],
            'rangeFactorPer9Inn' : year_data['stats']['rangeFactorPer9Inn'],
            'doublePlays' : year_data['stats']['doublePlays'],
            'triplePlays' : year_data['stats']['triplePlays'],
            'throwingErrors' : year_data['stats']['throwingErrors']
        }
        data.append(stat_dict) 

# 데이터 프레임 생성
df = pd.DataFrame(data)

# 데이터 프레임 출력
print(df)

데이터 프레임에 3루수가 아닌 지명타자로 출전했을때의 기록도 포함되어 있습니다. 지명타자는 수비를 하지 않기 때문에 수비 지표들이 0으로 나오거나 존재하지 않는데 DH(지명타자)에 해당하는 값들을 지워주겠습니다.

 

# 필요한 연도 데이터 필터링 및 데이터 프레임으로 변환
data = []
for year_data in arenado_stats['stats']:
    season = year_data['season']
    position = year_data['stats']['position']['abbreviation']
    if 2013 <= int(season) <= 2023 and position != 'DH':  # DH 제외
        stat_dict = {
            'Year': season,
            'Position': position,
            'Games Played': year_data['stats']['gamesPlayed'],
            'Games Started': year_data['stats']['gamesStarted'],
            'Innings': year_data['stats']['innings'],
            'Total Chances': year_data['stats']['chances'],
            'Put Outs': year_data['stats']['putOuts'],
            'Assists': year_data['stats']['assists'],
            'Errors': year_data['stats']['errors'],
            'Fielding Percentage': year_data['stats']['fielding'],
            'rangeFactorPerGame' : year_data['stats']['rangeFactorPerGame'],
            'rangeFactorPer9Inn' : year_data['stats']['rangeFactorPer9Inn'],
            'doublePlays' : year_data['stats']['doublePlays'],
            'triplePlays' : year_data['stats']['triplePlays'],
            'throwingErrors' : year_data['stats']['throwingErrors']
        }
        data.append(stat_dict)

# 데이터 프레임 생성
df = pd.DataFrame(data)

# 데이터 프레임 출력
print(df)

그럼 만든 데이터 프레임을 가지고 시각화를 해보겠습니다.

 

년도별 수비 통계 비교

우선 아레나도 선수한테 몇번의 수비 기회가 왔고 그 중 직접 베이스를 밟아 아웃시킨것과 송구를 해서 아웃시킨 것들이 얼마나 있는지 확인해보겠습니다.

# 그래프 객체 생성
fig = go.Figure()

# Total Chances 그리기
fig.add_trace(go.Scatter(x=df['Year'], y=df['Total Chances'], mode='lines+markers', name='Total Chances'))

# Put Outs 그리기
fig.add_trace(go.Scatter(x=df['Year'], y=df['Put Outs'], mode='lines+markers', name='Put Outs'))

# Assists 그리기
fig.add_trace(go.Scatter(x=df['Year'], y=df['Assists'], mode='lines+markers', name='Assists'))

# 레이아웃 설정
fig.update_layout(
    title="Yearly Fielding Stats Comparison",
    xaxis_title="Year",
    yaxis_title="Counts",
    legend_title="Legend",
    font=dict(
        family="Courier New, monospace",
        size=18,
        color="RebeccaPurple"
    )
)

# 그래프 표시
fig.show()

단축시즌이었던 2020시즌을 제외하고는 평균적으로 400번 이상 가까이 수비 기회가 있다는 것을 볼 수 있습니다. 또한, 3루수여서 직접 아웃을 시킨 것보다 송구를 해서 잡은 아웃이 더 많은 것을 알 수 있습니다.

 

년도별 실책 및 송구 실책  비교

# 그래프 객체 생성
fig = go.Figure()

# Errors 그리기
fig.add_trace(go.Scatter(x=df['Year'], y=df['Errors'], mode='lines+markers', name='실책'))

# Throwing Errors 그리기
fig.add_trace(go.Scatter(x=df['Year'], y=df['throwingErrors'], mode='lines+markers', name='송구 실책'))

# 레이아웃 설정
fig.update_layout(
    title="년도별 실책 및 투구 송구 비교",
    xaxis_title="년도",
    yaxis_title="수치",
    legend_title="범례"
)

# 그래프 표시
fig.show()

위에서 봤든 수비 기회가 400번 심지어 500번이 넘을 때도 있었는데 실책은 10 ~ 15개 정도를 기록하는 것을 볼 수 있습니다. 실책이 매우 적기 때문에 아레나도 선수가 어떻게 골드글러브를 10년 연속 받았는지 알 수 있습니다.

 

반응형

'야구 분석/Python'의 다른글

  • 현재글 놀란 아레나도 수비 지표 분석

관련글