Package: nfl-data-py
nfl_data_pynfl_data_py is a Python library for interacting with NFL data sourced fromnflfastR,nfldata,dynastyprocess, andDraft Scout.Includes import functions for play-by-play data, weekly data, seasonal data, rosters, win totals, scoring lines, officials, draft picks, draft pick values, schedules, team descriptive info, combine results and id mappings across various sites.InstallationUse the package managerpipto install nfl_data_py.pipinstallnfl_data_pyUsageimportnfl_data_pyasnflWorking with play-by-play datanfl.import_pbp_data(years,columns,downcast=True,cache=False,alt_path=None)Returns play-by-play data for the years and columns specifiedyears
: required, list of years to pull data for (earliest available is 1999)columns
: optional, list of columns to pull data fordowncast
: optional, converts float64 columns to float32, reducing memory usage by ~30%. Will slow down initial load speed ~50%cache
: optional, determines whether to pull pbp data from github repo or local cache generated by nfl.cache_pbp()alt_path
: optional, required if nfl.cache_pbp() is called using an alternate path to the default cachenfl.see_pbp_cols()returns list of columns available in play-by-play datasetWorking with weekly datanfl.import_weekly_data(years,columns,downcast)Returns weekly data for the years and columns specifiedyears
: required, list of years to pull data for (earliest available is 1999)columns
: optional, list of columns to pull data fordowncast
: converts float64 columns to float32, reducing memory usage by ~30%. Will slow down initial load speed ~50%nfl.see_weekly_cols()returns list of columns available in weekly datasetWorking with seasonal datanfl.import_seasonal_data(years,s_type)Returns seasonal data, including various calculated market share stats specific to receiversyears (List[int])
: required, list of years to pull data for (earliest available is 1999)s_type (str)
: optional (default 'REG') season type to include in average ('ALL','REG','POST')calculated receiving market share stats include:Columnis short fortgt_shtarget shareay_shair yards shareyac_shyards after catch sharewoprweighted opportunity ratingry_shreceiving yards sharertd_shreceiving TDs sharerfd_shreceiving 1st Downs sharertdfd_shreceiving TDs + 1st Downs sharedomdominator ratingw8domdominator rating, but weighted in favor of receiving yards over TDsyptmpareceiving yards per team pass attemptppr_shPPR fantasy points shareAdditional data importsnfl.import_seasonal_rosters(years,columns)Returns yearly roster information for the seasons specifiedyears
: required, list of years to pull data for (earliest available is 1999)columns
: optional, list of columns to pull data fornfl.import_weekly_rosters(years,columns)Returns per-game roster information for the seasons specifiedyears
: required, list of years to pull data for (earliest available is 1999)columns
: optional, list of columns to pull data fornfl.import_win_totals(years)Returns win total lines for years specifiedyears
: optional, list of years to pullnfl.import_sc_lines(years)Returns scoring lines for years specifiedyears
: optional, list of years to pullnfl.import_officials(years)Returns official information by game for the years specifiedyears
: optional, list of years to pullnfl.import_draft_picks(years)Returns list of draft picks for the years specifiedyears
: optional, list of years to pullnfl.import_draft_values()Returns relative values by generic draft pick according to various popular valuation methodsnfl.import_team_desc()Returns dataframe with color/logo/etc information for all NFL teamnfl.import_schedules(years)Returns dataframe with schedule information for years specifiedyears
: required, list of years to pull data for (earliest available is 1999)nfl.import_combine_data(years,positions)Returns dataframe with combine results for years and positions specifiedyears
: optional, list or range of years to pull data frompositions
: optional, list of positions to be pulled (standard format - WR/QB/RB/etc.)nfl.import_ids(columns,ids)Returns dataframe with mapped ids for all players across most major NFL and fantasy football data platformscolumns
: optional, list of columns to returnids
: optional, list of ids to returnnfl.import_ngs_data(stat_type,years)Returns dataframe with specified NGS datastat_type (str)
: required, type of stats to pull (passing, rushing, receiving)years
: optional, list of years to return data fornfl.import_depth_charts(years)Returns dataframe with depth chart datayears
: optional, list of years to return data fornfl.import_injuries(years)Returns dataframe of injury reportsyears
: optional, list of years to return data fornfl.import_qbr(years,level,frequency)Returns dataframe with QBR historyyears
: optional, years to return data forlevel
: optional, competition level to return data for, nfl or college, default nflfrequency
: optional, frequency to return data for, weekly or season, default seasonnfl.import_seasonal_pfr(s_type,years)Returns a dataframe of season-aggregated data sourced from players' pages on pro-football-reference.com. E.g.Patrick Mahomess_type (str)
: required, the type of stat data to request. Must be one of pass, rec, or rush.years (List[int])
: optional, years to return data fornfl.import_weekly_pfr(s_type,years)Returns a dataframe of per-game data sourced from players' advanced gamelog pages on pro-football-reference.com. E.g.Mahomes in 2022s_type (str)
: required, the type of stat data to request. Must be one of pass, rec, or rush.years (List[int])
: optional, years to return data fornfl.import_snap_counts(years)Returns dataframe with snap count recordsyears
: optional, list of years to return data fornfl.import_ftn_data(years,columns=None,downcast=True,thread_requests=False)Returns dataframe with FTN charting dataFTN Data manually charts plays and has graciously provided a subset of their
charting data to be published via the nflverse. Data is available from the 2022
season onwards and is charted within 48 hours following each game. This data
is released under theCC-BY-SA 4.0Creative Commons license and attribution must be made toFTN Data via nflverseyears (List[int])
: required, years to get weekly data for
columns (List[str])
: optional, only return these columns
downcast (bool)
: optional, convert float64 to float32, default True
thread_requests (bool)
: optional use thread pool to read files, default FalseAdditional featuresnfl.cache_pbp(years,downcast=True,alt_path=None)Caches play-by-play data locally to speed up download time. If years specified have already been cached they will be overwritten, so if using in-season must cache 1x per week to catch most recent datayears
: required, list or range of years to cachedowncast
: optional, converts float64 columns to float32, reducing memory usage by ~30%. Will slow down initial load speed ~50%alt_path
:optional, alternate path to store pbp cache - default is in program created user Local foldernfl.clean_nfl_data(df)Runs descriptive data (team name, player name, etc.) through various cleaning processesdf
: required, dataframe to be cleanedRecognitionI'd like to recognize all ofBen Baldwin,Sebastian Carl, andLee Sharpefor making this data freely available and easy to access. I'd also like to thankTan Ho, who has been an invaluable resource as I've worked through this project, and Josh Kazan for the resources and assistance he's provided.ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.LicenseMIT