Helpers
Some helper functions are made available in NFLData.jl
for use in loading and cleaning data. Not all helper functions that are available in {nflreadr}
have been translated to NFLData.jl
, such as nflreadr::join_coalesce()
–these functions are general enough that they are considered beyond the scope of this package.
NFLData.helpers.clean_player_names
— Methodclean_player_names(player_name::AbstractString; lowercase::Bool = false, convert_lastfirst::Bool = true, use_name_database::Bool = true, convert_to_ascii::Bool = true)
Clean up player names for merges. Can convert names to lowercase, swap first/last names, remove diacritics, and also rely on manual overrides as specified by nflverse devs.
Examples
julia> clean_player_names("Tom Brady")
"Tom Brady"
julia> clean_player_names("Melvin Gordon Jr.")
"Melvin Gordon"
julia> clean_player_names("Melvin Gordon Jr.",lowercase = true)
"melvin gordon"
julia> clean_player_names("Alexander Armah")
"Alex Armah"
julia> clean_player_names("Moritz Böhringer")
"Moritz Bohringer"
julia> clean_player_names("Gordon Jr., Melvin", convert_lastfirst = true)
"Melvin Gordon"
NFLData.helpers.clean_homeaway
— Methodclean_homeaway(dataframe::AbstractDataFrame;invert = missing)
Take a dataframe that is formatted with one record for a game between two teams and pivot it such that there exists two records per game, one for each team.
Columns should be formatted such that any columns for data belonging to the home team are prefixed or suffixed with "home" and "home", likewise for away teams.
Pass in a list of columns to invert
to have these values multiplied by -1 before being returned to the new dataframe (such as margin of victory, which may be +7 for a home team and -7 for an away team in a given game).
NFLData.gameinfo.most_recent_season
— Functionmost_recent_season(roster::Bool = false)
Return the most recent NFL season (including in-progress season).
If roster=true
, the upcoming NFL season is returned if the system date is March 15th or later. Defaults to false
.
NFLData.gameinfo.get_current_week
— Functionget_current_week(use_date::Bool = false)
Return the current/upcoming week of the NFL season. Uses the schedules by default, can be swapped to use date-based heuristics by passing use_date=true
.
Examples
julia> # if using Dates; today() == "2024-09-15"
julia>get_current_week()
2
NFLData.helpers.clean_team_abbrs
— Methodclean_team_abbrs(team::AbstractString; current_location::Bool = true, keep_non_matches::Bool = true)
Clean abbreviations of teams to NFLverse friendly abbreviations.
Examples
julia> clean_team_abbrs("SD")
"LAC"
NFLData.helpers.nflverse_game_id
— Methodnflverse_game_id(season::Number,week::Number,away::AbstractString,home::AbstractString)
Check and calculate an nflverse game ID.
Examples
julia> nflverse_game_id(2022, 2, "LAC", "KC")
"2022_02_LAC_KC"