Jensen-holm
commited on
Commit
·
cee03a3
1
Parent(s):
b808783
new setup with the github actions updates.
Browse files- README.md +29 -11
- requirements.txt +0 -2
- src/dtypes.py +0 -91
- src/statcast_era_pitches.py +0 -51
- statcast_era_pitches.parquet +0 -3
README.md
CHANGED
@@ -4,25 +4,43 @@ license: mit
|
|
4 |
|
5 |
# statcast-era-pitches
|
6 |
|
7 |
-
This
|
8 |
|
9 |
-
##
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
|
17 |
-
```
|
18 |
-
|
19 |
|
20 |
-
|
|
|
|
|
21 |
```
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
2. import the data/statcast.parquet file into library of choice
|
28 |
|
|
|
|
4 |
|
5 |
# statcast-era-pitches
|
6 |
|
7 |
+
This dataset contains every pitch thrown in Major League Baseball from 2015 through present, and is updated weekly. See the **Updates** section for detials.
|
8 |
|
9 |
+
## Usage
|
10 |
|
11 |
+
***Tidyverse***
|
12 |
+
```r
|
13 |
+
library(tidyverse)
|
14 |
|
15 |
+
statcast_pitches <- read_parquet(
|
16 |
+
"https://huggingface.co/datasets/Jensen-holm/statcast-era-pitches/resolve/main/data/statcast_era_pitches.parquet"
|
17 |
+
)
|
18 |
+
```
|
19 |
|
20 |
+
***Pandas***
|
21 |
|
22 |
+
```python
|
23 |
+
import pandas as pd
|
24 |
|
25 |
+
statcast_pitches = pd.read_parquet(
|
26 |
+
"https://huggingface.co/datasets/Jensen-holm/statcast-era-pitches/resolve/main/data/statcast_era_pitches.parquet"
|
27 |
+
)
|
28 |
```
|
29 |
|
30 |
+
***Polars***
|
31 |
+
|
32 |
+
```python
|
33 |
+
import polars as pl
|
34 |
+
|
35 |
+
statcast_pitches = pl.read_parquet(
|
36 |
+
"https://huggingface.co/datasets/Jensen-holm/statcast-era-pitches/resolve/main/data/statcast_era_pitches.parquet"
|
37 |
+
)
|
38 |
+
```
|
39 |
+
|
40 |
+
## Variable Docs
|
41 |
|
42 |
+
Documentation on the columns/features in this dataset can be found [here](https://baseballsavant.mlb.com/csv-docs).
|
43 |
|
44 |
+
## Updates
|
|
|
45 |
|
46 |
+
This data set is updated once per week through GitHub Actions in [this repository](). the [pybaseball]() package is used to retrieve new statcast pitch level data each monday morning at 12:00 PM ET. It is then pushed to this huggingface dataset.
|
requirements.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
polars==1.9.0
|
2 |
-
pybaseball==2.2.7
|
|
|
|
|
|
src/dtypes.py
DELETED
@@ -1,91 +0,0 @@
|
|
1 |
-
import polars as pl
|
2 |
-
|
3 |
-
# statcast data types: https://baseballsavant.mlb.com/csv-docs (this is where pybaseball gets the data from)
|
4 |
-
|
5 |
-
|
6 |
-
COLUMN_DTYPES: dict[str, pl.DataTypeClass] = {
|
7 |
-
# string columns
|
8 |
-
"pitch_type": pl.String,
|
9 |
-
"game_date": pl.String,
|
10 |
-
"game_type": pl.String,
|
11 |
-
"p_throws": pl.String,
|
12 |
-
"stand": pl.String,
|
13 |
-
"home_team": pl.String,
|
14 |
-
"away_team": pl.String,
|
15 |
-
"description": pl.String,
|
16 |
-
"des": pl.String,
|
17 |
-
"events": pl.String,
|
18 |
-
"type": pl.String,
|
19 |
-
"if_fielding_alignment": pl.String,
|
20 |
-
"of_fielding_alignment": pl.String,
|
21 |
-
"sv_id": pl.String, # has an underscore in it so pl.Int64 failed
|
22 |
-
# float columns
|
23 |
-
"release_speed": pl.Float64,
|
24 |
-
"release_pos_x": pl.Float64,
|
25 |
-
"release_pos_y": pl.Float64,
|
26 |
-
"release_pos_z": pl.Float64,
|
27 |
-
"spin_rate": pl.Float64,
|
28 |
-
"release_spin": pl.Float64,
|
29 |
-
"break_angle": pl.Float64,
|
30 |
-
"zone": pl.Int64, # ??
|
31 |
-
"hit_location": pl.Float64,
|
32 |
-
"pfx_x": pl.Float64,
|
33 |
-
"pfx_z": pl.Float64,
|
34 |
-
"plate_x": pl.Float64,
|
35 |
-
"plate_z": pl.Float64,
|
36 |
-
"inning": pl.Float64,
|
37 |
-
"vx0": pl.Float64,
|
38 |
-
"vy0": pl.Float64,
|
39 |
-
"vz0": pl.Float64,
|
40 |
-
"ax": pl.Float64,
|
41 |
-
"ay": pl.Float64,
|
42 |
-
"az": pl.Float64,
|
43 |
-
"sz_top": pl.Float64,
|
44 |
-
"sz_bot": pl.Float64,
|
45 |
-
"hit_distance": pl.Float64,
|
46 |
-
"launch_speed": pl.Float64,
|
47 |
-
"launch_angle": pl.Float64,
|
48 |
-
"launch_speed_angle": pl.Float64,
|
49 |
-
"effective_speed": pl.Float64,
|
50 |
-
"release_spin": pl.Float64,
|
51 |
-
"release_extension": pl.Float64,
|
52 |
-
"release_pos_y": pl.Float64,
|
53 |
-
"estimated_ba_using_speedangle": pl.Float64,
|
54 |
-
"estimated_woba_using_speedangle": pl.Float64,
|
55 |
-
"woba_value": pl.Float64,
|
56 |
-
"woba_denom": pl.Float64,
|
57 |
-
"babip_value": pl.Float64,
|
58 |
-
"iso_value": pl.Float64,
|
59 |
-
"spin_axis": pl.Int64,
|
60 |
-
"delta_home_win_exp": pl.Float64,
|
61 |
-
"delta_run_exp": pl.Float64,
|
62 |
-
# int columns
|
63 |
-
"balls": pl.Int64,
|
64 |
-
"strikes": pl.Int64,
|
65 |
-
"outs_when_up": pl.Int64,
|
66 |
-
"batter": pl.Int64,
|
67 |
-
"pitcher": pl.Int64,
|
68 |
-
"game_year": pl.Int64,
|
69 |
-
"on_3b": pl.Int64,
|
70 |
-
"on_2b": pl.Int64,
|
71 |
-
"on_1b": pl.Int64,
|
72 |
-
"game_pk": pl.Int64,
|
73 |
-
"fielder_2": pl.Int64,
|
74 |
-
"fielder_3": pl.Int64,
|
75 |
-
"fielder_4": pl.Int64,
|
76 |
-
"fielder_5": pl.Int64,
|
77 |
-
"fielder_6": pl.Int64,
|
78 |
-
"fielder_7": pl.Int64,
|
79 |
-
"fielder_8": pl.Int64,
|
80 |
-
"fielder_9": pl.Int64,
|
81 |
-
"at_bat_number": pl.Int64,
|
82 |
-
"pitch_number": pl.Int64,
|
83 |
-
"home_score": pl.Int64,
|
84 |
-
"away_score": pl.Int64,
|
85 |
-
"bat_score": pl.Int64,
|
86 |
-
"post_home_score": pl.Int64,
|
87 |
-
"post_away_score": pl.Int64,
|
88 |
-
"post_bat_score": pl.Int64,
|
89 |
-
"bat_speed": pl.Float64,
|
90 |
-
"swing_length": pl.Float64,
|
91 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/statcast_era_pitches.py
DELETED
@@ -1,51 +0,0 @@
|
|
1 |
-
import polars as pl
|
2 |
-
import pybaseball
|
3 |
-
import datetime
|
4 |
-
import os
|
5 |
-
|
6 |
-
from dtypes import COLUMN_DTYPES
|
7 |
-
|
8 |
-
import warnings
|
9 |
-
|
10 |
-
# pybaseball has a lot of FutureWarnings with pandas
|
11 |
-
warnings.filterwarnings("ignore", category=FutureWarning)
|
12 |
-
|
13 |
-
|
14 |
-
DATA_DIR = os.path.join("..", "data")
|
15 |
-
COMPRESSION = "zstd"
|
16 |
-
|
17 |
-
|
18 |
-
def get_statcast_era_pitches(
|
19 |
-
end_year: int = datetime.datetime.now().year - 1,
|
20 |
-
) -> pl.DataFrame:
|
21 |
-
assert end_year > 2015, f"end year must be > 2015, not '{end_year}'"
|
22 |
-
|
23 |
-
pitches_by_year: list[pl.DataFrame] = []
|
24 |
-
dt_range = range(2015, end_year)
|
25 |
-
|
26 |
-
for i, year in enumerate(dt_range):
|
27 |
-
print(f"Season {i + 1} / {len(dt_range)}")
|
28 |
-
_pitches: pl.DataFrame = pl.from_pandas(
|
29 |
-
pybaseball.statcast(
|
30 |
-
start_dt=f"{year}-03-01",
|
31 |
-
end_dt=f"{year}-12-01",
|
32 |
-
verbose=False,
|
33 |
-
parallel=True,
|
34 |
-
),
|
35 |
-
schema_overrides=COLUMN_DTYPES,
|
36 |
-
rechunk=True,
|
37 |
-
)
|
38 |
-
pitches_by_year.append(_pitches)
|
39 |
-
|
40 |
-
return pl.concat(
|
41 |
-
pitches_by_year,
|
42 |
-
rechunk=True,
|
43 |
-
)
|
44 |
-
|
45 |
-
|
46 |
-
if __name__ == "__main__":
|
47 |
-
statcast_era_pitches: pl.DataFrame = get_statcast_era_pitches(end_year=2024)
|
48 |
-
statcast_era_pitches.write_parquet(
|
49 |
-
os.path.join(DATA_DIR, "statcast_era_pitches.parquet"),
|
50 |
-
compression=COMPRESSION,
|
51 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statcast_era_pitches.parquet
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:e9b897ae79e9d3d135aad9be485924825f953aea9f9252c6f04b560b727d6e41
|
3 |
-
size 575389953
|
|
|
|
|
|
|
|