Skip to content

Instantly share code, notes, and snippets.

@jgamblin
Last active July 21, 2021 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgamblin/31f6864fb27e4d2b04407c83a2f23585 to your computer and use it in GitHub Desktop.
Save jgamblin/31f6864fb27e4d2b04407c83a2f23585 to your computer and use it in GitHub Desktop.
MLB 2021 Fastest Pitches
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "spanish-update",
"metadata": {},
"outputs": [],
"source": [
"from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator)\n",
"from pybaseball import statcast\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pybaseball\n",
"import seaborn as sns\n",
"import warnings\n",
"\n",
"warnings.filterwarnings('ignore')\n",
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
"pybaseball.cache.enable()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "confused-indiana",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is a large query, it may take a moment to complete\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 0/246 [00:00<?, ?it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Skipping offseason dates\n",
"Skipping offseason dates\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 246/246 [00:02<00:00, 82.98it/s] \n"
]
}
],
"source": [
"data = statcast(start_dt='2021-01-01', end_dt='2021-12-31')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "international-button",
"metadata": {},
"outputs": [],
"source": [
"STL = data.loc[(data['home_team'])=='STL']\n",
"STL = STL.append(data.loc[(data['away_team'])=='STL'])\n",
"CHC = data.loc[(data['home_team'])=='CHC']\n",
"CHC = CHC.append(data.loc[(data['away_team'])=='CHC'])\n",
"BOS = data.loc[(data['home_team'])=='BOS']\n",
"BOS = BOS.append(data.loc[(data['away_team'])=='BOS'])\n"
]
},
{
"cell_type": "markdown",
"id": "generous-eating",
"metadata": {},
"source": [
"### STL Fastest Pitch"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "earlier-summer",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>player_name</th>\n",
" <th>release_speed</th>\n",
" <th>game_date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2005</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>103.2</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1951</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>102.5</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2066</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>102.4</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2462</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>102.1</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2334</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>101.9</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2140</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>101.9</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2719</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>101.7</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2562</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>101.7</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2286</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>101.5</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2036</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>101.5</td>\n",
" <td>2021-04-14</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" player_name release_speed game_date\n",
"2005 Hicks, Jordan 103.2 2021-04-07\n",
"1951 Hicks, Jordan 102.5 2021-04-07\n",
"2066 Hicks, Jordan 102.4 2021-04-07\n",
"2462 Hicks, Jordan 102.1 2021-04-07\n",
"2334 Hicks, Jordan 101.9 2021-04-07\n",
"2140 Hicks, Jordan 101.9 2021-04-07\n",
"2719 Hicks, Jordan 101.7 2021-04-07\n",
"2562 Hicks, Jordan 101.7 2021-04-07\n",
"2286 Hicks, Jordan 101.5 2021-04-07\n",
"2036 Hicks, Jordan 101.5 2021-04-14"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"STL[['player_name', 'release_speed', 'game_date']].sort_values(by='release_speed', ascending=False).head(10)"
]
},
{
"cell_type": "markdown",
"id": "another-approval",
"metadata": {},
"source": [
"### Cubs Fastest Pitch "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "spectacular-keeping",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>player_name</th>\n",
" <th>release_speed</th>\n",
" <th>game_date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>3927</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.5</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3347</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.4</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3583</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.3</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2954</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.3</td>\n",
" <td>2021-05-12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3711</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.2</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4069</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.2</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3499</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.1</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4305</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.1</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3112</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>101.0</td>\n",
" <td>2021-05-12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2175</th>\n",
" <td>Alvarado, José</td>\n",
" <td>101.0</td>\n",
" <td>2021-07-05</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" player_name release_speed game_date\n",
"3927 Clase, Emmanuel 101.5 2021-05-11\n",
"3347 Clase, Emmanuel 101.4 2021-05-11\n",
"3583 Clase, Emmanuel 101.3 2021-05-11\n",
"2954 Clase, Emmanuel 101.3 2021-05-12\n",
"3711 Clase, Emmanuel 101.2 2021-05-11\n",
"4069 Clase, Emmanuel 101.2 2021-05-11\n",
"3499 Clase, Emmanuel 101.1 2021-05-11\n",
"4305 Clase, Emmanuel 101.1 2021-05-11\n",
"3112 Clase, Emmanuel 101.0 2021-05-12\n",
"2175 Alvarado, José 101.0 2021-07-05"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"CHC[['player_name', 'release_speed', 'game_date']].sort_values(by='release_speed', ascending=False).head(10)"
]
},
{
"cell_type": "markdown",
"id": "italic-genesis",
"metadata": {},
"source": [
"### RedSox Fastest Pitch "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cardiovascular-champion",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>player_name</th>\n",
" <th>release_speed</th>\n",
" <th>game_date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>3138</th>\n",
" <td>deGrom, Jacob</td>\n",
" <td>101.2</td>\n",
" <td>2021-04-28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3636</th>\n",
" <td>Chapman, Aroldis</td>\n",
" <td>101.0</td>\n",
" <td>2021-07-18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1643</th>\n",
" <td>Eovaldi, Nathan</td>\n",
" <td>100.7</td>\n",
" <td>2021-06-04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>785</th>\n",
" <td>Cole, Gerrit</td>\n",
" <td>100.7</td>\n",
" <td>2021-06-27</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3186</th>\n",
" <td>Glasnow, Tyler</td>\n",
" <td>100.7</td>\n",
" <td>2021-04-06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3733</th>\n",
" <td>deGrom, Jacob</td>\n",
" <td>100.7</td>\n",
" <td>2021-04-28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3260</th>\n",
" <td>deGrom, Jacob</td>\n",
" <td>100.6</td>\n",
" <td>2021-04-28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3389</th>\n",
" <td>deGrom, Jacob</td>\n",
" <td>100.6</td>\n",
" <td>2021-04-28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1583</th>\n",
" <td>Eovaldi, Nathan</td>\n",
" <td>100.6</td>\n",
" <td>2021-06-04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>deGrom, Jacob</td>\n",
" <td>100.5</td>\n",
" <td>2021-04-28</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" player_name release_speed game_date\n",
"3138 deGrom, Jacob 101.2 2021-04-28\n",
"3636 Chapman, Aroldis 101.0 2021-07-18\n",
"1643 Eovaldi, Nathan 100.7 2021-06-04\n",
"785 Cole, Gerrit 100.7 2021-06-27\n",
"3186 Glasnow, Tyler 100.7 2021-04-06\n",
"3733 deGrom, Jacob 100.7 2021-04-28\n",
"3260 deGrom, Jacob 100.6 2021-04-28\n",
"3389 deGrom, Jacob 100.6 2021-04-28\n",
"1583 Eovaldi, Nathan 100.6 2021-06-04\n",
"101 deGrom, Jacob 100.5 2021-04-28"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"BOS[['player_name', 'release_speed', 'game_date']].sort_values(by='release_speed', ascending=False).head(10)"
]
},
{
"cell_type": "markdown",
"id": "isolated-cookbook",
"metadata": {},
"source": [
"### MLB Fastest Pitch "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "criminal-mobile",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>player_name</th>\n",
" <th>release_speed</th>\n",
" <th>game_date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2390</th>\n",
" <td>Chapman, Aroldis</td>\n",
" <td>103.4</td>\n",
" <td>2021-06-19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2005</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>103.2</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2849</th>\n",
" <td>Chapman, Aroldis</td>\n",
" <td>102.8</td>\n",
" <td>2021-05-18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2721</th>\n",
" <td>Alvarado, José</td>\n",
" <td>102.5</td>\n",
" <td>2021-05-11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1951</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>102.5</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1538</th>\n",
" <td>Chapman, Aroldis</td>\n",
" <td>102.4</td>\n",
" <td>2021-04-29</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2066</th>\n",
" <td>Hicks, Jordan</td>\n",
" <td>102.4</td>\n",
" <td>2021-04-07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2989</th>\n",
" <td>Clase, Emmanuel</td>\n",
" <td>102.2</td>\n",
" <td>2021-06-30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2728</th>\n",
" <td>Chapman, Aroldis</td>\n",
" <td>102.2</td>\n",
" <td>2021-06-19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3370</th>\n",
" <td>Chapman, Aroldis</td>\n",
" <td>102.2</td>\n",
" <td>2021-05-08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" player_name release_speed game_date\n",
"2390 Chapman, Aroldis 103.4 2021-06-19\n",
"2005 Hicks, Jordan 103.2 2021-04-07\n",
"2849 Chapman, Aroldis 102.8 2021-05-18\n",
"2721 Alvarado, José 102.5 2021-05-11\n",
"1951 Hicks, Jordan 102.5 2021-04-07\n",
"1538 Chapman, Aroldis 102.4 2021-04-29\n",
"2066 Hicks, Jordan 102.4 2021-04-07\n",
"2989 Clase, Emmanuel 102.2 2021-06-30\n",
"2728 Chapman, Aroldis 102.2 2021-06-19\n",
"3370 Chapman, Aroldis 102.2 2021-05-08"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fastest = data.sort_values(by='release_speed', ascending=False)\n",
"fastest[['player_name', 'release_speed', 'game_date']].head(10)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment