Skip to main content

attr: player_on_court.__doc__

Project description

License Contact

Adding data about players on court in NBA games.

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

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.

Code example

>>> from nba_api.stats.endpoints import playbyplayv2
>>> import player_on_court.player_on_court as poc
>>>
>>> pbp = playbyplayv2.PlayByPlayV2(game_id="0022100001").play_by_play.get_data_frame()
>>> pbp_with_players = poc.adding_player_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 = poc.replace_id_on_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']

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

player_on_court-0.2.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file player_on_court-0.2.0.tar.gz.

File metadata

  • Download URL: player_on_court-0.2.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for player_on_court-0.2.0.tar.gz
Algorithm Hash digest
SHA256 254e599d7ba394b0031c87cbec85b5774469b31c3b1b362dafb75a795e738375
MD5 0c0204648b68d07f024a313f8e326270
BLAKE2b-256 244e0f92e275bef7b2c7afc282081ead817c3fe2c9d7de4af20fa2c343fe76b2

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