Canada Basketball Analytics

Top 5 Regular Season NBA Bubble Performances by Canadians

With the NBA playoffs coming to a close shortly we thought we would take a look at the Top 5 Regular Season NBA Bubble Performances by Canadians. We will first cover off the results and then the how-to on the method to retrieve the data and calculate both the Efficiency and Fantasy Scoring metrics.

Top 5 Performances by Efficiency

Efficiency is calculated by (PTS + REB + AST + STL + BLK – Missed Field Goals – Missed Free Throws – TO)

1) Chris Boucher – Efficiency 35

Matchup: Win TOR @ MIL on August 10th 2020

PTSREBASTSTLBLKMissed FGMissed FTTO
2511222610

2) Brandon Clarke – Efficiency 31

Matchup: Loss MEM @ POR on July 31st 2020

PTSREBASTSTLBLKMissed FGMissed FTTO
217212110

3) Dillon Brooks – Efficiency 27

Matchup: Win MEM vs. MILK on August 13th 2020

PTSREBASTSTLBLKMissed FGMissed FTTO
312201621

TIED 4) Chris Boucher – Efficiency 25

Matchup: Win TOR @ PHI on August 12th 2020

PTSREBASTSTLBLKMissed FGMissed FTTO
199004511

TIED 4) Kelly Olynyk – Efficiency 25

Matchup: Win MIA @ DEN on August 1st 2020

PTSREBASTSTLBLKMissed FGMissed FTTO
205311302

TIED 4) Nickeil Alexander-Walker – Efficiency 25

Matchup: Loss NOP @ ORL on August 13th 2020

PTSREBASTSTLBLKMissed FGMissed FTTO
291710706

Top 5 Performances by NBA Fantasy Points

NBA Fantasy Points uses the following values for each statistic: PTS 1, REBS 1.2, AST 1.5, STL 3, BLOCK 3, TO -1

1) Chris Boucher – Fantasy Points 53.2

Matchup: Win TOR @ MIL on August 10th 2020

PTSREBSASTSTLBLKTO
25112220

2) Jamal Murray – Fantasy Points 50.4

Matchup: Win DEN vs. UTA on August 8th 2020

PTSREBSASTSTLBLKTO
23128012

3) Kelly Olynyk – Fantasy Points 42.2

Matchup: Win MIA vs. BOS on August 8th 2020

PTSREBSASTSTLBLKTO
1568211

4) Brandon Clarke – Fantasy Points 41.4

Matchup: Loss MEM @ POR on July 31st 2020

PTSREBSASTSTLBLKTO
2172120

5) Dillon Brooks – Fantasy Points 41.2

Matchup: Loss MEM @ TOR on August 9th 2020

PTSREBSASTSTLBLKTO
2562303

The How-To

Now for the fun part (at least in my mind), how did we mine this data and calculate both Efficiency and Fantasy Points. A couple of prerequisites are required.

Anaconda

Anaconda is a free and open-source distribution of the Python and R programming languages for scientific computing that aims to simplify package management and deployment. To download and install please visit the Anaconda homepage.

NBA_API

NBA_API is an API Client package to access the APIs for NBA.com. To install you can use the below command

pip install nba_api

For more information around NBA_API, check them out on GitHub.

The Code to download the data

Also available via GitHub

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 17 17:01:41 2020

@author: Andrew
"""

#Combined for all the Canadian NBA Players

from nba_api.stats.static import players
from nba_api.stats.endpoints import playergamelog
from nba_api.stats.library.parameters import SeasonAll
from nba_api.stats import endpoints
import pandas as pd 
import time 


#All NBA Players names to grab for 
playerList = [
#'Tristan Thompson', 
'Trey Lyles',
'Shai Gilgeous-Alexander',
'RJ Barrett', 
'Oshae Brissett', 
'Nickeil Alexander-Walker', 
'Naz Mitrou-Long',
'Mfiondu Kabengele',
'Marial Shayok',
'Luguentz Dort',
'Kyle Alexander',
'Khem Birch',
'Kelly Olynyk',
'Jamal Murray',
'Ignas Brazdeikis',
'Dwight Powell',
'Dillon Brooks',
'Cory Joseph',
'Chris Boucher',
'Brandon Clarke',
'Andrew Wiggins',
#Mychal Mulder
]

seasonToGrab = '2019'
#filename = <insert filename path here> 
filename = filename  + seasonToGrab + '-CombinedPlayerBoxScores.csv'

######Create the dataframe by loading in a player outside of the loop 
player_dict = players.get_players()
time.sleep(2)
#Loop through player listing 
df_player_games_total = pd.DataFrame()
# Use ternary operator or write function 
# Names are case sensitive
player = [player for player in player_dict if player['full_name'] == 'Tristan Thompson'][0]
player_id = player['id']
#Call the API endpoint passing in lebron's ID & which season 
gamelog_player = playergamelog.PlayerGameLog(player_id=player_id, season = seasonToGrab)
time.sleep(2)
#Converts gamelog object into a pandas dataframe
#can also convert to JSON or dictionary  
df_player_games = gamelog_player.get_data_frames()[0]
df_player_games.insert(2,'Player_Name','Tristan Thompson')
df_player_games_total = df_player_games
time.sleep(2)
######

#####Loop through list of players and append together 
for i in playerList: 
    # Use ternary operator or write function 
    # Names are case sensitive
    player = [player for player in player_dict if player['full_name'] == i][0]
    player_id = player['id']
    #Call the API endpoint passing in lebron's ID & which season 
    gamelog_player = playergamelog.PlayerGameLog(player_id=player_id, season = seasonToGrab)
    time.sleep(2)
    #Converts gamelog object into a pandas dataframe
    #can also convert to JSON or dictionary  
    df_player_games = gamelog_player.get_data_frames()[0]
    #df_player_games
    df_player_games.insert(2,'Player_Name',i)
    time.sleep(2)
    df_player_games_total = df_player_games_total.append(df_player_games)
    print(i) 

#Export to CSV 
df_player_games_total.to_csv(filename)
     

Excel Formulas

After executing the above code to download all the data you need to do some filtering and some calculations, this could also be completed within Python but sometimes I like to do the quick and dirty data manipulation like this in Excel. Sometimes Excel is a very underrated tool.

Since the code to mine the data was for the whole regular season of 2019-2020 I simply deleted any data from before the months of July and August of 2020 (column F – GAME_DATE).

Once we have a narrowed down the dataset I threw the data into a Pivot Table (see Pivots tab within the above excel document). This pivot table provided me an easier way to visualize the stats by player.

Next, we did calculations for the Missed FG measure (FGA – FGM) in column N of the Pivots tab and Missed FT measure (FTA – FTM) in column O of the Pivots tab.

Calculating Efficiency in column P (PTS + REB + AST + STL + BLK – Missed Field Goals – Missed Free Throws – TO) was done simply by an excel formula for the equivalent rows/columns of data of the formula.

Likewise, calculating Fantasy Points (PTS 1, REBS 1.2, AST 1.5, STL 3, BLOCK 3, TO -1) in column S was done with an excel formula and multiplying the correct columns by the values above.

Now that we have all of the Efficiency and Fantasy Points calculated we can use the Excel Rank formula to figure out which player had the highest values per each measure (columns R and S of the Pivots tab).