Skip to main content

COLLEGE_BASEBALL — additional Python functions

Hand-written wrappers, loaders, and helpers in sportsdataverse.college_baseball not covered by the generated API-endpoint reference above.

stats.ncaa.org​

college_baseball_re24​

college_baseball_re24(seasons: 'Union[int, List[int], None]' = None, *, state: 'Optional[pl.DataFrame]' = None, return_as_pandas: 'bool' = False) -> "Union[pl.DataFrame, 'pd.DataFrame']"

sportsdataverse.baseball.college_run_expectancy.college_baseball_re24 fixed to league="college_baseball".

Parameters

ParameterTypeDefaultDescription
seasonsUnion[int, List[int], None]NoneSee the core function.
stateOptional[DataFrame]NoneSee the core function.
return_as_pandasboolFalseReturn pandas.DataFrame instead of polars.

Returns

see the core function's Returns table.

col_nametypedescription
base_statecharacter3-char base occupancy code ("_" = empty, "1"/"2"/"3" = occupied), e.g. "1_3" for runners on first and third.
outsintegerOuts at the start of the base-out state (0-2).
run_expectancydoubleEmpirical mean runs scored from this state through the end of the half-inning (RE24).
nintegerNumber of plate appearances observed starting in this base-out state.

Example

from sportsdataverse.baseball.college_baseball.college_baseball_re import college_baseball_state, college_baseball_re24
state = college_baseball_state(raw)
matrix = college_baseball_re24(state=state)

college_baseball_state​

college_baseball_state(plays: 'Dict[str, Any]') -> 'pl.DataFrame'

sportsdataverse.baseball.college_run_expectancy.college_baseball_state fixed to league="college_baseball".

Parameters

ParameterTypeDefaultDescription
playsDict[str, Any]Raw payload from espn_college_baseball_game_plays(event_id, return_parsed=False).

Returns

see the core function's Returns table.

col_nametypedescription
game_idcharacter
inninginteger
halfcharacter
base_statecharacter
outsinteger
runs_beforeinteger
runs_afterinteger
batting_team_idcharacter
play_seqinteger
score_diffinteger

Example

from sportsdataverse.baseball.college_baseball.college_baseball_re import college_baseball_state
state = college_baseball_state(raw)

college_baseball_wpa​

college_baseball_wpa(seasons: 'Union[int, List[int], None]' = None, *, state: 'Optional[pl.DataFrame]' = None, results: 'Optional[pl.DataFrame]' = None, return_as_pandas: 'bool' = False) -> "Union[pl.DataFrame, 'pd.DataFrame']"

sportsdataverse.baseball.college_run_expectancy.college_baseball_wpa fixed to league="college_baseball".

Parameters

ParameterTypeDefaultDescription
seasonsUnion[int, List[int], None]NoneSee the core function.
stateOptional[DataFrame]NoneSee the core function.
resultsOptional[DataFrame]NoneSee the core function.
return_as_pandasboolFalseReturn pandas.DataFrame instead of polars.

Returns

see the core function's Returns table.

col_nametypedescription
game_idcharacterESPN event id for the game (join key to the schedule).
play_seqintegerGame-global sequential plate-appearance order.
re_beforedoubleRE24 of the base-out state before the PA.
re_afterdoubleRE24 of the base-out state after the PA.
run_valuedoublere_after minus re_before, plus runs scored on the play.
wpadoubleHome-perspective win-probability added.

Example

from sportsdataverse.baseball.college_baseball.college_baseball_re import college_baseball_wpa
wpa = college_baseball_wpa(state=state, results=results)

Play-by-play processing​

decompose_college_baseball_plays​

decompose_college_baseball_plays(rows: "'list[dict]'", *, return_as_pandas: 'bool' = False) -> "'Union[pl.DataFrame, pd.DataFrame]'"

Decompose pre-extracted play rows into the full PBP_SCHEMA frame.

The row-level half of parse_college_baseball_ncaa_pbp -- the play-text decomposition engine without the HTML extraction. This is the entry point for sources that already hold the base play fields, e.g. the legacy R-era baseballr-data trees (2012-2023: description/inning/ inning_top_bot/batting/fielding/score), so legacy and freshly captured games resolve into IDENTICAL pbp columns.

Parameters

ParameterTypeDefaultDescription
rowslist[dict]One dict per play. Recognized keys (all optional except description): contest_id, inning (int), inning_top_bot ("top"/"bot"), batting, fielding, play_number, score_away/score_home (ints) or a combined score string ("3-2", away-home), and description. Unrecognized keys are ignored; play_number defaults to the 1-based position in rows.
return_as_pandasboolFalseReturn a pandas.DataFrame instead of polars.

Returns

One row per input play with every text-derivable PBP_SCHEMA column populated (play_type, hit/out flags, rbi, pitch_sequence, runner movement, ...). Empty input returns a zero-row frame with the documented schema.

col_nametypedescription
contest_idcharacter
inninginteger
inning_top_botcharacter
battingcharacter
fieldingcharacter
play_numberinteger
score_awayinteger
score_homeinteger
battercharacterMLBAM player id of the batter.
play_typecharacter
hit_trajectorycharacter
fielded_positioncharacter
is_hitlogical
is_outlogical
strikeout_typecharacter
is_sacrificelogical
sac_typecharacter
is_double_playlogical
rbiinteger
count_ballsinteger
count_strikesinteger
pitch_sequencecharacter
error_positioncharacter
unearnedlogical
runs_scoredinteger
scoring_runnerscharacter
runners_advancedcharacter
outs_on_playinteger
is_scoring_playlogicalFlag indicating that the play put points on the board (1 = scoring play, 0 = not).
descriptioncharacter

Example

from sportsdataverse.baseball.college_baseball import decompose_college_baseball_plays
df = decompose_college_baseball_plays(
[{"inning": 1, "inning_top_bot": "top", "score": "0-0",
"description": "Jack Moss singled to left field (1-2 KBFX)."}]
)
print(df.select("play_type", "is_hit", "pitch_sequence").row(0))