Skip to main content

attr: nba-on-court.__doc__

Project description

License Contact

Adding data about players on court in NBA games.

nba_on_court package allows you to add to play-by-play data information about players who were on court at any given time.

Instalation

pip install nba-on-court

Important: This package does not request play-by-play data from NBA website. You need to get them in advance, for example, using nba_api package.

https://github.com/swar/nba_api

How it work

Play-by-play NBA data contains information about each event in the game (throw, substitution, foul, etc.) and players who participated in it (PLAYER1_ID, PLAYER2_ID, PLAYER3_ID).

From this data, we get a list of players who were on court in this quarter. Then, we need to filter this list to 10 people who started quarter. This is done by analyzing substitutions in quarter.

I will soon describe a more complete mechanism for processing play-by-play data to obtain information about players on court in an article.

In package two main functions: players_on_court and players_name.

players_on_court takes play-by-play data as input and returns it with 10 columns of the PLAYER_ID of players who were on court at each time.

players_name allows you to replace PLAYER_ID with first and last name of player. This allows user to understand exactly which players were on court (few know PLAYER_ID all players in NBA),but it is not necessary to do this before calculations, because the player’s NAME_SURNAME is not unique, unlike PLAYER_ID.

Code example

>>> from nba_api.stats.endpoints import playbyplayv2
>>> import nba_on_court.nba_on_court as noc
>>>
>>> pbp = playbyplayv2.PlayByPlayV2(game_id="0022100001").play_by_play.get_data_frame()
>>> pbp_with_players = noc.players_on_court(pbp)
>>> len(pbp_with_players.columns) - len(pbp.columns)
10
>>> players_id = list(pbp_with_players.iloc[0, 34:].reset_index(drop=True))
>>> print(players_id)
[201142, 1629651, 201933, 201935, 203925, 201572, 201950, 1628960, 203114, 203507]
>>> players_name = noc.players_name(players_id)
>>> print(players_name)
['Kevin Durant', 'Nic Claxton', 'Blake Griffin', 'James Harden', 'Joe Harris',
'Brook Lopez', 'Jrue Holiday', 'Grayson Allen', 'Khris Middleton', 'Giannis Antetokounmpo']

You can also replace the PLAYER_ID with the player’s name in the entire data frame at once.

>>> cols = ["PLAYER1", "PLAYER2", "PLAYER3", "PLAYER4", "PLAYER5", "PLAYER6", "PLAYER7", "PLAYER8", "PLAYER9", "PLAYER10"]
>>> pbp_with_players.loc[:, cols] = pbp_with_players.loc[:, cols].apply(noc.players_name, result_type="expand")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nba-on-court-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file nba-on-court-0.1.1.tar.gz.

File metadata

  • Download URL: nba-on-court-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.9

File hashes

Hashes for nba-on-court-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2b4e3d90c6a5f4c37b5d5454c944c13f12aacfe80b7cc04460d83e7ea8a01061
MD5 3005b95ae38d37f40456b950e84b85ea
BLAKE2b-256 b3bb2badf6831b1a7c2f166ac79bda4a5eacb1612a651d6e4c1832f26c2a32dd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page