Jensen-holm commited on
Commit
69d38f1
·
1 Parent(s): a03f36a

Getting all statcast era (2015 thru last year) data using pybaseball and

Browse files
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ *.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,8 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ # statcast-era-pitches
6
+
7
+ tabular dataset that contains all mlb pitch data in the modern statcast era (2015-2023) up through last year.
8
+
data/statcast.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f048066e0c60adc235e7adf58784d4aa01e5efae8d8cdbf7e6b1857305646591
3
+ size 370832392
src/statcast_through_last_year.ipynb ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pybaseball\n",
10
+ "import polars as pl\n",
11
+ "import datetime\n",
12
+ "from tqdm import tqdm\n",
13
+ "import os\n",
14
+ "\n",
15
+ "DATA_DIR = os.path.join(\"..\", \"data\")\n",
16
+ "STATCAST_ERA = range(2015, datetime.datetime.now().year - 1)"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 2,
22
+ "metadata": {},
23
+ "outputs": [
24
+ {
25
+ "name": "stdout",
26
+ "output_type": "stream",
27
+ "text": [
28
+ "\u001b[1mAll done! ✨ 🍰 ✨\u001b[0m\n",
29
+ "\u001b[34m2 files \u001b[0mleft unchanged.\n"
30
+ ]
31
+ }
32
+ ],
33
+ "source": [
34
+ "# format code (does so in all files)\n",
35
+ "!black ."
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 3,
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "# statcast data types: https://baseballsavant.mlb.com/csv-docs (this is where pybaseball gets the data from)\n",
45
+ "\n",
46
+ "COLUMN_DTYPES: dict[str, pl.DataType] = {\n",
47
+ " # string columns\n",
48
+ " \"pitch_type\": pl.String,\n",
49
+ " \"game_date\": pl.String,\n",
50
+ " \"game_type\": pl.String,\n",
51
+ " \"p_throws\": pl.String,\n",
52
+ " \"stand\": pl.String,\n",
53
+ " \"home_team\": pl.String,\n",
54
+ " \"away_team\": pl.String,\n",
55
+ " \"description\": pl.String,\n",
56
+ " \"des\": pl.String,\n",
57
+ " \"events\": pl.String,\n",
58
+ " \"type\": pl.String,\n",
59
+ " \"if_fielding_alignment\": pl.String,\n",
60
+ " \"of_fielding_alignment\": pl.String,\n",
61
+ " \"sv_id\": pl.String, # has an underscore in it so pl.Int32 failed\n",
62
+ " # float columns\n",
63
+ " \"release_speed\": pl.Float32,\n",
64
+ " \"release_pos_x\": pl.Float32,\n",
65
+ " \"release_pos_y\": pl.Float32,\n",
66
+ " \"release_pos_z\": pl.Float32,\n",
67
+ " \"spin_rate\": pl.Float32,\n",
68
+ " \"release_spin\": pl.Float32,\n",
69
+ " \"break_angle\": pl.Float32,\n",
70
+ " \"zone\": pl.Float32, # ??\n",
71
+ " \"hit_location\": pl.Float32,\n",
72
+ " \"pfx_x\": pl.Float32,\n",
73
+ " \"pfx_z\": pl.Float32,\n",
74
+ " \"plate_x\": pl.Float32,\n",
75
+ " \"plate_z\": pl.Float32,\n",
76
+ " \"inning\": pl.Float32,\n",
77
+ " \"vx0\": pl.Float32,\n",
78
+ " \"vy0\": pl.Float32,\n",
79
+ " \"vz0\": pl.Float32,\n",
80
+ " \"ax\": pl.Float32,\n",
81
+ " \"ay\": pl.Float32,\n",
82
+ " \"az\": pl.Float32,\n",
83
+ " \"sz_top\": pl.Float32,\n",
84
+ " \"sz_bot\": pl.Float32,\n",
85
+ " \"hit_distance\": pl.Float32,\n",
86
+ " \"launch_speed\": pl.Float32,\n",
87
+ " \"launch_angle\": pl.Float32,\n",
88
+ " \"launch_speed_angle\": pl.Float32,\n",
89
+ " \"effective_speed\": pl.Float32,\n",
90
+ " \"release_spin\": pl.Float32,\n",
91
+ " \"release_extension\": pl.Float32,\n",
92
+ " \"release_pos_y\": pl.Float32,\n",
93
+ " \"estimated_ba_using_speedangle\": pl.Float32,\n",
94
+ " \"estimated_woba_using_speedangle\": pl.Float32,\n",
95
+ " \"woba_value\": pl.Float32,\n",
96
+ " \"woba_denom\": pl.Float32,\n",
97
+ " \"babip_value\": pl.Float32,\n",
98
+ " \"iso_value\": pl.Float32,\n",
99
+ " \"spin_axis\": pl.Float32,\n",
100
+ " \"delta_home_win_exp\": pl.Float32,\n",
101
+ " \"delta_run_exp\": pl.Float32,\n",
102
+ " # int columns\n",
103
+ " \"balls\": pl.Int32,\n",
104
+ " \"strikes\": pl.Int32,\n",
105
+ " \"outs_when_up\": pl.Int32,\n",
106
+ " \"batter\": pl.Int32,\n",
107
+ " \"pitcher\": pl.Int32,\n",
108
+ " \"game_year\": pl.Int32,\n",
109
+ " \"on_3b\": pl.Int32,\n",
110
+ " \"on_2b\": pl.Int32,\n",
111
+ " \"on_1b\": pl.Int32,\n",
112
+ " \"game_pk\": pl.Int32,\n",
113
+ " \"fielder_2\": pl.Int32,\n",
114
+ " \"fielder_3\": pl.Int32,\n",
115
+ " \"fielder_4\": pl.Int32,\n",
116
+ " \"fielder_5\": pl.Int32,\n",
117
+ " \"fielder_6\": pl.Int32,\n",
118
+ " \"fielder_7\": pl.Int32,\n",
119
+ " \"fielder_8\": pl.Int32,\n",
120
+ " \"fielder_9\": pl.Int32,\n",
121
+ " \"at_bat_number\": pl.Int32,\n",
122
+ " \"pitch_number\": pl.Int32,\n",
123
+ " \"home_score\": pl.Int32,\n",
124
+ " \"away_score\": pl.Int32,\n",
125
+ " \"bat_score\": pl.Int32,\n",
126
+ " \"post_home_score\": pl.Int32,\n",
127
+ " \"post_away_score\": pl.Int32,\n",
128
+ " \"post_bat_score\": pl.Int32,\n",
129
+ "}"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 4,
135
+ "metadata": {},
136
+ "outputs": [
137
+ {
138
+ "name": "stderr",
139
+ "output_type": "stream",
140
+ "text": [
141
+ "100%|██████████| 211/211 [00:41<00:00, 5.10it/s]\n",
142
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
143
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
144
+ "100%|██████████| 214/214 [00:42<00:00, 4.98it/s]\n",
145
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
146
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
147
+ "100%|██████████| 214/214 [00:43<00:00, 4.95it/s]\n",
148
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
149
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
150
+ "100%|██████████| 214/214 [00:43<00:00, 4.95it/s]\n",
151
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
152
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
153
+ "100%|██████████| 225/225 [00:47<00:00, 4.77it/s]\n",
154
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
155
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
156
+ "100%|██████████| 97/97 [00:19<00:00, 5.06it/s]n]\n",
157
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
158
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
159
+ "100%|██████████| 246/246 [00:50<00:00, 4.83it/s]\n",
160
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
161
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
162
+ "100%|██████████| 246/246 [00:51<00:00, 4.76it/s]\n",
163
+ "/Users/jensen/Documents/projects/bsbl/statcast-era-pitches/venv/lib/python3.12/site-packages/pybaseball/statcast.py:85: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
164
+ " final_data = pd.concat(dataframe_list, axis=0).convert_dtypes(convert_string=False)\n",
165
+ "100%|██████████| 8/8 [06:14<00:00, 46.85s/season]\n"
166
+ ]
167
+ },
168
+ {
169
+ "name": "stdout",
170
+ "output_type": "stream",
171
+ "text": [
172
+ "Rows: 5479763\n",
173
+ "Columns: 92\n",
174
+ "$ pitch_type <str> 'FF', 'FC', 'FF', 'FC', 'FF', 'FF', 'FF', 'FF', 'FC', 'KC'\n",
175
+ "$ game_date <str> '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000', '2015-11-01 00:00:00.000000000'\n",
176
+ "$ release_speed <f32> 96.0999984741211, 93.0999984741211, 97.0, 93.5999984741211, 97.0999984741211, 96.5, 96.5999984741211, 97.5999984741211, 92.0, 86.69999694824219\n",
177
+ "$ release_pos_x <f32> -2.0199999809265137, -1.659999966621399, -1.6399999856948853, -1.5800000429153442, -1.7000000476837158, -1.6200000047683716, -1.3899999856948853, -1.5099999904632568, -1.8899999856948853, -1.6200000047683716\n",
178
+ "$ release_pos_z <f32> 6.25, 6.239999771118164, 6.300000190734863, 6.239999771118164, 6.300000190734863, 6.210000038146973, 6.400000095367432, 6.409999847412109, 6.25, 6.269999980926514\n",
179
+ "$ player_name <str> 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade', 'Davis, Wade'\n",
180
+ "$ batter <i32> 527038, 527038, 527038, 527038, 527038, 527038, 624424, 624424, 624424, 624424\n",
181
+ "$ pitcher <i32> 451584, 451584, 451584, 451584, 451584, 451584, 451584, 451584, 451584, 451584\n",
182
+ "$ events <str> 'strikeout', None, None, None, None, None, 'single', None, None, None\n",
183
+ "$ description <str> 'called_strike', 'foul', 'foul', 'ball', 'foul', 'foul', 'hit_into_play', 'ball', 'called_strike', 'swinging_strike'\n",
184
+ "$ spin_dir <i64> None, None, None, None, None, None, None, None, None, None\n",
185
+ "$ spin_rate_deprecated <i64> None, None, None, None, None, None, None, None, None, None\n",
186
+ "$ break_angle_deprecated <i64> None, None, None, None, None, None, None, None, None, None\n",
187
+ "$ break_length_deprecated <i64> None, None, None, None, None, None, None, None, None, None\n",
188
+ "$ zone <f32> 13.0, 9.0, 14.0, 14.0, 5.0, 5.0, 4.0, 11.0, 5.0, 14.0\n",
189
+ "$ des <str> 'Wilmer Flores called out on strikes.', 'Wilmer Flores called out on strikes.', 'Wilmer Flores called out on strikes.', 'Wilmer Flores called out on strikes.', 'Wilmer Flores called out on strikes.', 'Wilmer Flores called out on strikes.', 'Michael Conforto singles on a line drive to left fielder Alex Gordon.', 'Michael Conforto singles on a line drive to left fielder Alex Gordon.', 'Michael Conforto singles on a line drive to left fielder Alex Gordon.', 'Michael Conforto singles on a line drive to left fielder Alex Gordon.'\n",
190
+ "$ game_type <str> 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W'\n",
191
+ "$ stand <str> 'R', 'R', 'R', 'R', 'R', 'R', 'L', 'L', 'L', 'L'\n",
192
+ "$ p_throws <str> 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'\n",
193
+ "$ home_team <str> 'NYM', 'NYM', 'NYM', 'NYM', 'NYM', 'NYM', 'NYM', 'NYM', 'NYM', 'NYM'\n",
194
+ "$ away_team <str> 'KC', 'KC', 'KC', 'KC', 'KC', 'KC', 'KC', 'KC', 'KC', 'KC'\n",
195
+ "$ type <str> 'S', 'S', 'S', 'B', 'S', 'S', 'X', 'B', 'S', 'S'\n",
196
+ "$ hit_location <f32> 2.0, None, None, None, None, None, 7.0, None, None, None\n",
197
+ "$ bb_type <str> None, None, None, None, None, None, 'line_drive', None, None, None\n",
198
+ "$ balls <i32> 1, 1, 1, 0, 0, 0, 1, 0, 0, 0\n",
199
+ "$ strikes <i32> 2, 2, 2, 2, 1, 0, 2, 2, 1, 0\n",
200
+ "$ game_year <i32> 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015\n",
201
+ "$ pfx_x <f32> -0.10000000149011612, 0.5, -0.27000001072883606, 0.6499999761581421, -0.5799999833106995, -0.4300000071525574, -0.1899999976158142, -0.10000000149011612, 0.46000000834465027, 0.8100000023841858\n",
202
+ "$ pfx_z <f32> 1.4299999475479126, 0.44999998807907104, 1.1799999475479126, 0.5699999928474426, 1.4299999475479126, 1.1399999856948853, 1.3899999856948853, 1.309999942779541, 0.5899999737739563, -1.0\n",
203
+ "$ plate_x <f32> -0.9300000071525574, 0.7799999713897705, 1.3200000524520874, 2.9200000762939453, 0.25999999046325684, -0.05000000074505806, -0.6399999856948853, -0.8500000238418579, -0.05000000074505806, 1.059999942779541\n",
204
+ "$ plate_z <f32> 1.6200000047683716, 1.5499999523162842, 2.4700000286102295, 2.2300000190734863, 2.740000009536743, 2.559999942779541, 2.690000057220459, 3.1500000953674316, 2.700000047683716, 1.5800000429153442\n",
205
+ "$ on_3b <i32> None, None, None, None, None, None, None, None, None, None\n",
206
+ "$ on_2b <i32> 624424, 624424, 624424, None, None, None, None, None, None, None\n",
207
+ "$ on_1b <i32> None, None, None, 624424, 624424, 624424, None, None, None, None\n",
208
+ "$ outs_when_up <i32> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2\n",
209
+ "$ inning <f32> 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0\n",
210
+ "$ inning_topbot <str> 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot', 'Bot'\n",
211
+ "$ hc_x <f64> None, None, None, None, None, None, 83.65, None, None, None\n",
212
+ "$ hc_y <f64> None, None, None, None, None, None, 120.15, None, None, None\n",
213
+ "$ tfs_deprecated <i64> None, None, None, None, None, None, None, None, None, None\n",
214
+ "$ tfs_zulu_deprecated <i64> None, None, None, None, None, None, None, None, None, None\n",
215
+ "$ fielder_2 <i32> 460077, 460077, 460077, 460077, 460077, 460077, 460077, 460077, 460077, 460077\n",
216
+ "$ umpire <i64> None, None, None, None, None, None, None, None, None, None\n",
217
+ "$ sv_id <str> '151102_003434', '151102_003407', '151102_003338', '151102_003312', '151102_003241', '151102_003211', '151102_003124', '151102_003104', '151102_003043', '151102_003021'\n",
218
+ "$ vx0 <f32> 3.1401078701019287, 4.990328311920166, 8.631301879882812, 9.893107414245605, 6.809913635253906, 5.320800304412842, 2.5009560585021973, 2.0603606700897217, 3.529362440109253, 4.466300964355469\n",
219
+ "$ vy0 <f32> -140.72560119628906, -136.39666748046875, -141.8474884033203, -136.60494995117188, -142.01861572265625, -141.39695739746094, -141.4544219970703, -143.01341247558594, -134.7886505126953, -127.161376953125\n",
220
+ "$ vz0 <f32> -9.348184585571289, -6.388609409332275, -6.829428672790527, -5.019608974456787, -6.757789611816406, -6.0896148681640625, -6.951479911804199, -5.739217758178711, -3.657803773880005, -1.4352083206176758\n",
221
+ "$ ax <f32> -2.0280001163482666, 5.004000186920166, -5.4120001792907715, 6.078999996185303, -9.14799976348877, -6.785999774932861, -3.068000078201294, -1.815999984741211, 4.705999851226807, 7.535999774932861\n",
222
+ "$ ay <f32> 34.779998779296875, 28.834999084472656, 31.551000595092773, 26.354999542236328, 32.250999450683594, 34.05400085449219, 32.17900085449219, 34.584999084472656, 26.79800033569336, 27.1200008392334\n",
223
+ "$ az <f32> -11.706000328063965, -25.322999954223633, -15.189000129699707, -24.25, -11.956000328063965, -16.038000106811523, -12.607000350952148, -13.479999542236328, -24.395999908447266, -42.277000427246094\n",
224
+ "$ sz_top <f32> 3.5399999618530273, 3.5399999618530273, 3.5399999618530273, 3.5399999618530273, 3.5399999618530273, 3.5399999618530273, 3.390000104904175, 3.390000104904175, 3.390000104904175, 3.390000104904175\n",
225
+ "$ sz_bot <f32> 1.559999942779541, 1.559999942779541, 1.559999942779541, 1.559999942779541, 1.559999942779541, 1.559999942779541, 1.5, 1.5, 1.5, 1.5\n",
226
+ "$ hit_distance_sc <i64> None, None, None, None, None, None, 178, None, None, None\n",
227
+ "$ launch_speed <f32> None, None, None, None, None, None, 96.0, None, None, None\n",
228
+ "$ launch_angle <f32> None, None, None, None, None, None, 8.0, None, None, None\n",
229
+ "$ effective_speed <f32> 95.4000015258789, 92.19999694824219, 96.4000015258789, 92.80000305175781, 96.0, 95.9000015258789, 95.9000015258789, 96.69999694824219, 91.19999694824219, 84.80000305175781\n",
230
+ "$ release_spin_rate <i64> 2463, 2705, 2362, 2724, 2401, 2337, 2312, 2255, 2755, 2509\n",
231
+ "$ release_extension <f32> 6.400000095367432, 5.900000095367432, 6.300000190734863, 6.0, 6.099999904632568, 6.400000095367432, 6.199999809265137, 6.199999809265137, 5.900000095367432, 5.5\n",
232
+ "$ game_pk <i32> 446277, 446277, 446277, 446277, 446277, 446277, 446277, 446277, 446277, 446277\n",
233
+ "$ pitcher.1 <i64> 451584, 451584, 451584, 451584, 451584, 451584, 451584, 451584, 451584, 451584\n",
234
+ "$ fielder_2.1 <i64> 460077, 460077, 460077, 460077, 460077, 460077, 460077, 460077, 460077, 460077\n",
235
+ "$ fielder_3 <i32> 543333, 543333, 543333, 543333, 543333, 543333, 543333, 543333, 543333, 543333\n",
236
+ "$ fielder_4 <i32> 450314, 450314, 450314, 450314, 450314, 450314, 450314, 450314, 450314, 450314\n",
237
+ "$ fielder_5 <i32> 519058, 519058, 519058, 519058, 519058, 519058, 519058, 519058, 519058, 519058\n",
238
+ "$ fielder_6 <i32> 444876, 444876, 444876, 444876, 444876, 444876, 444876, 444876, 444876, 444876\n",
239
+ "$ fielder_7 <i32> 460086, 460086, 460086, 460086, 460086, 460086, 460086, 460086, 460086, 460086\n",
240
+ "$ fielder_8 <i32> 456715, 456715, 456715, 456715, 456715, 456715, 456715, 456715, 456715, 456715\n",
241
+ "$ fielder_9 <i32> 449181, 449181, 449181, 449181, 449181, 449181, 449181, 449181, 449181, 449181\n",
242
+ "$ release_pos_y <f32> 54.5, 54.5, 54.5, 54.5, 54.5, 54.5, 54.5, 54.5, 54.5, 54.5\n",
243
+ "$ estimated_ba_using_speedangle <f32> None, None, None, None, None, None, 0.7269999980926514, None, None, None\n",
244
+ "$ estimated_woba_using_speedangle <f32> None, None, None, None, None, None, 0.7149999737739563, None, None, None\n",
245
+ "$ woba_value <f32> 0.0, None, None, None, None, None, 0.8999999761581421, None, None, None\n",
246
+ "$ woba_denom <f32> 1.0, None, None, None, None, None, 1.0, None, None, None\n",
247
+ "$ babip_value <f32> 0.0, None, None, None, None, None, 1.0, None, None, None\n",
248
+ "$ iso_value <f32> 0.0, None, None, None, None, None, 0.0, None, None, None\n",
249
+ "$ launch_speed_angle <f32> None, None, None, None, None, None, 4.0, None, None, None\n",
250
+ "$ at_bat_number <i32> 94, 94, 94, 94, 94, 94, 93, 93, 93, 93\n",
251
+ "$ pitch_number <i32> 6, 5, 4, 3, 2, 1, 4, 3, 2, 1\n",
252
+ "$ pitch_name <str> '4-Seam Fastball', 'Cutter', '4-Seam Fastball', 'Cutter', '4-Seam Fastball', '4-Seam Fastball', '4-Seam Fastball', '4-Seam Fastball', 'Cutter', 'Knuckle Curve'\n",
253
+ "$ home_score <i32> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2\n",
254
+ "$ away_score <i32> 7, 7, 7, 7, 7, 7, 7, 7, 7, 7\n",
255
+ "$ bat_score <i32> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2\n",
256
+ "$ fld_score <i64> 7, 7, 7, 7, 7, 7, 7, 7, 7, 7\n",
257
+ "$ post_away_score <i32> 7, 7, 7, 7, 7, 7, 7, 7, 7, 7\n",
258
+ "$ post_home_score <i32> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2\n",
259
+ "$ post_bat_score <i32> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2\n",
260
+ "$ post_fld_score <i64> 7, 7, 7, 7, 7, 7, 7, 7, 7, 7\n",
261
+ "$ if_fielding_alignment <str> 'Standard', 'Standard', 'Standard', 'Strategic', 'Strategic', 'Strategic', 'Infield shift', 'Infield shift', 'Infield shift', 'Infield shift'\n",
262
+ "$ of_fielding_alignment <str> 'Strategic', 'Strategic', 'Strategic', 'Strategic', 'Standard', 'Standard', 'Standard', 'Standard', 'Standard', 'Standard'\n",
263
+ "$ spin_axis <f32> None, None, None, None, None, None, None, None, None, None\n",
264
+ "$ delta_home_win_exp <f32> -0.0010000000474974513, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0010000000474974513, 0.0, 0.0, 0.0\n",
265
+ "$ delta_run_exp <f32> -0.21199999749660492, 0.0, 0.0, 0.01600000075995922, -0.052000001072883606, -0.03500000014901161, 0.15399999916553497, 0.007000000216066837, -0.02199999988079071, -0.01600000075995922\n",
266
+ "\n"
267
+ ]
268
+ }
269
+ ],
270
+ "source": [
271
+ "all_statcast_df: pl.DataFrame = pl.concat(\n",
272
+ " [\n",
273
+ " pl.from_pandas(\n",
274
+ " pybaseball.statcast(\n",
275
+ " start_dt=f\"{year}-01-01\",\n",
276
+ " end_dt=f\"{year}-12-31\",\n",
277
+ " verbose=False,\n",
278
+ " ),\n",
279
+ " schema_overrides=COLUMN_DTYPES,\n",
280
+ " rechunk=True, # makes sure that the data is aligned in memory\n",
281
+ " )\n",
282
+ " for year in tqdm(STATCAST_ERA, unit=\"season\")\n",
283
+ " ],\n",
284
+ " rechunk=True,\n",
285
+ ")\n",
286
+ "\n",
287
+ "all_statcast_df.glimpse()"
288
+ ]
289
+ },
290
+ {
291
+ "cell_type": "code",
292
+ "execution_count": 5,
293
+ "metadata": {},
294
+ "outputs": [],
295
+ "source": [
296
+ "\n",
297
+ "all_statcast_df.write_parquet(\n",
298
+ " os.path.join(DATA_DIR, \"statcast.parquet\"),\n",
299
+ " compression=\"zstd\",\n",
300
+ ")\n"
301
+ ]
302
+ }
303
+ ],
304
+ "metadata": {
305
+ "kernelspec": {
306
+ "display_name": ".venv",
307
+ "language": "python",
308
+ "name": "python3"
309
+ },
310
+ "language_info": {
311
+ "codemirror_mode": {
312
+ "name": "ipython",
313
+ "version": 3
314
+ },
315
+ "file_extension": ".py",
316
+ "mimetype": "text/x-python",
317
+ "name": "python",
318
+ "nbconvert_exporter": "python",
319
+ "pygments_lexer": "ipython3",
320
+ "version": "3.12.3"
321
+ }
322
+ },
323
+ "nbformat": 4,
324
+ "nbformat_minor": 2
325
+ }
src/this_year.ipynb ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import polars as pl\n",
10
+ "import os\n",
11
+ "\n",
12
+ "DATA_DIR = os.path.join(\"..\", \"data\")"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": null,
18
+ "metadata": {},
19
+ "outputs": [],
20
+ "source": []
21
+ }
22
+ ],
23
+ "metadata": {
24
+ "kernelspec": {
25
+ "display_name": "venv",
26
+ "language": "python",
27
+ "name": "python3"
28
+ },
29
+ "language_info": {
30
+ "codemirror_mode": {
31
+ "name": "ipython",
32
+ "version": 3
33
+ },
34
+ "file_extension": ".py",
35
+ "mimetype": "text/x-python",
36
+ "name": "python",
37
+ "nbconvert_exporter": "python",
38
+ "pygments_lexer": "ipython3",
39
+ "version": "3.12.3"
40
+ }
41
+ },
42
+ "nbformat": 4,
43
+ "nbformat_minor": 2
44
+ }