pypuck package

Submodules

pypuck.pypuck module

The pypuck functions are used as wrapper functions to call the NHL.com publicly available API’s.

pypuck.pypuck.attendance(regular=True, playoffs=True, start_season=None, end_season=None)

Query the NHL attendance number from 1975 to 2019 from the NHL records API. The attendance represents annual attendance numbers for all teams.

The user can specify to return either the regular season attendance, playoff attendance numbers, or both.

The function will display a chart showing the attendance over the specified time period.

Parameters:
  • regular (boolean (default True)) – Whether to query seasonal regular season attendance data.
  • playoffs (boolean (default True)) – Whether to query seasonal playoff attendance data.
  • start_season (int (default None)) – The start season is integer ranging from 1975 to 2018.
  • end_season (int (default None)) – The end season is integer ranging from 1976 to 2019.
Returns:

It wil display attendance numbers in an Altair chart.

Return type:

altair.vegalite.v3.api.Chart

Examples

>>> from pypuck import pypuck
>>> pypuck.attendance(regular=True, playoffs=True,
                      start_season=2000, end_season=2019)
...
pypuck.pypuck.draft_pick(pick_number=1, round_number=None, year=None)

The function returns information about draft picks for the specified parameters and stores them in a pandas data frame.

If year is not specified, then all of the draft picks for all year will be returned.

If no round is specified the data frame will include all players with chosen pick number from every round.

There are cases when even though user entered valid parameters, the output would be empty if a pick number didn’t exist in a specified round, an assert error would be raised.

Parameters:
  • pick_number (int (default 1)) – Desired pick number, must be in the range [1,38]. If nothing is specified, picks first draft in all rounds.
  • round_number (int (default None)) – Desired round number, must be in the range [1,25]
  • year (int (default None)) – Year in which a draft took place. Must be YYYY format, that contains year in a range [1963,2019].
Returns:

Drafts with specified parameters.

Return type:

pandas.core.DataFrame

Examples

>>> from pypuck import pypuck
>>> pick_number = 9
>>> round_number = 7
>>> year = 2000
>>> pypuck.draft_pick(pick_number = pick_number,
                      round_number=round_number, year=year)
pypuck.pypuck.player_stats(start_date=None, end_date=None)

Query the top 100 player’s stats (sorted by total points) from the players summary report endpoint on the NHL.com API.

The stats are queried on an aggregated game-by-game basis for a range of dates. If no date is specified the function will return the players stats for the current season. The stats to be returned are restricted to the regular season.

The valid dates range from the start of the 1917 season until the current day.

The function will return the current season’s stats if the arguments are blank (i.e. left as None).

You can find the glossary pertaining to the returned columns by going to http://www.nhl.com/stats/glossary.

Parameters:
  • start_date (str (default None)) – The stat start date string in ‘YYYY-MM-DD’ format.
  • end_date (str (default None)) – The stat end date string in ‘YYYY-MM-DD’ format.
Returns:

The player’s stats in a dataframe sorted by total points.

Return type:

pandas.core.DataFrame

Examples

>>> from pypuck import pypuck
>>> pypuck.player_stats(start_date='2019-10-02', end_date='2020-02-28')
assists | evGoals | evPoints | faceoffWinPct | ...
--------------------------------------------------
   67   |    27   |    66    |    0.51641    | ...
--------------------------------------------------
...
pypuck.pypuck.team_stats(start_season='20192020', end_season='20192020')

Get team season stats specified by start year or start year and end year. If no year is specified then the year 2019-2020 is default. If an end year is specified then the start year is also to be provided. year is to be provided in a 2 year format of YYYYYYYY.

The valid seasons range from the 1917 season until the current season.

You can find the glossary pertaining to the returned columns by going to http://www.nhl.com/stats/glossary.

Parameters:
  • start_season (str) – The stat start year string in ‘YYYYYYYY’ format.
  • end_season (str) – The stat end year string in ‘YYYYYYYY’ format.
Returns:

The team’s seasonal stats in a dataframe.

Return type:

pandas.core.DataFrame

Examples

>>> from pypuck import pypuck
>>> start_season = '19801981'
>>> end_season = '19891990'
>>> pypuck.team_stats(start_season=start_season, end_season=end_season)
faceoffWinPct | gamesPlayed | goalsAgainst | goalsAgainstPerGame | ...
-----------------------------------------------------------------------
   0.481361   |      82     |     251      |        3.06097      | ...
-----------------------------------------------------------------------
...

Module contents