from datascience import * import numpy as np Table.interactive_plots()
Our first dataset today comes from Basketball Reference. It contains per-game averages of players in the 2019-2020 NBA season.
Run the cell below to load it in, select the relevant columns, and do some data cleaning.
Note: Most of the interesting data comes from the "better" players in the league; we will only look at players who averaged at least 10 points per game in the season. This isn't perfect, since there were plenty of good players who averaged less than 10 points per game.
nba = Table.read_table('data/nba-2020.csv') \ .select('Player', 'Pos', 'Tm', 'PTS', 'TRB', 'AST', '3PA', '3P%') \ .where('3PA', are.not_equal_to(0)) def remove_code(name): return name[:name.index('\\')] def get_court(pos): if 'G' in pos: return 'Guard' else: return 'Forward' nba = nba.with_columns('Player', nba.apply(remove_code, 'Player'), 'Pos', nba.apply(get_court, 'Pos')) \ .where('PTS', are.above(10))
|Marvin Bagley III||Forward||SAC||14.2||7.5||0.8||1.7||0.182|
... (163 rows omitted)
A description of each column:
'Pos': general position (either Forward or Guard)
'Tm': abbreviated team
'PTS': average number of points scored per game
'TRB': average number of rebounds per game (a player receives a rebound when they grab the ball after someone misses)
'AST': average number of assists per game (a player receives an assist when they pass the ball to someone who then scores)
'3PA': average number of three-point shots attempted per game (a three point shot is one from behind a certain line, which is between 22-24 feet from the basket)
'3P%': average proportion of three-point shots that go in
nba.group('Pos', np.mean).select('Pos', 'PTS mean', 'TRB mean', 'AST mean')
|Pos||PTS mean||TRB mean||AST mean|
nba.group('Pos', np.mean).select('Pos', 'PTS mean', 'TRB mean', 'AST mean').barh('Pos')