Measuring the Success of NBA Players According to their Years Spent in College

by Esteban De la Vega

The goal of this project is to analyze the correlation between a basketball player’s time in college and his performance at a professional level. Prior to a collective bargaining agreement in 2005, high schoolers, granted they were talented enough, could be drafted into the NBA without having been enrolled in college or without being a year removed from high school graduation. Thereon, there has been a recent trend of players who play one year in college and then transition into the NBA. This project will assess whether preparing for a longer unpaid period leads to further success in a player's professional career.

This project compares two data sources: all the NBA drafts begining in 1988 onwards and All-NBA team selections dating back to 1988. It will only take into account first-round draft selections and will count all All-NBA selections even if a player has multiple ones.


In [35]:
import sys                             
import pandas as pd                    
import matplotlib.pyplot as plt          
import datetime as dt                  
import numpy as np                     
import html5lib
from bs4 import BeautifulSoup 
import seaborn.apionly as sns          
from pandas.io import data, wb         


from plotly.offline import iplot, iplot_mpl  
import plotly.graph_objs as go               
import plotly                                
import cufflinks as cf                       
cf.set_config_file(offline=True, offline_show_link=False)


%matplotlib inline             
plotly.offline.init_notebook_mode()

print('Python version:', sys.version)
print('Pandas version: ', pd.__version__)
print('Plotly version: ', plotly.__version__)
print('Today: ', dt.date.today())


Python version: 3.5.1 |Anaconda 2.4.1 (x86_64)| (default, Dec  7 2015, 11:24:55) 
[GCC 4.2.1 (Apple Inc. build 5577)]
Pandas version:  0.17.1
Plotly version:  1.9.10
Today:  2016-05-08

Players selected into All-NBA teams:

By using the read_html function of html5lib, we are able to read the data from Basketball-Reference.com exactly as it is displayed on the website. We then convert the data into a pd.DataFrame and adjust the columns and shape up the variables.


In [4]:
# Code  reading allnba team selections since the 1988-1989 season.
url = 'http://www.basketball-reference.com/awards/all_league.html'
allnba = pd.read_html(url)
allnba = allnba[0]
allnba.columns = ['Year','League','All-NBA Team','Player1','Player2','Player3','Player4','Player5']
allnba = allnba.drop('League',1)
allnba = allnba.head(106)
allnba


Out[4]:
Year All-NBA Team Player1 Player2 Player3 Player4 Player5
0 2014-15 1st Marc Gasol C Anthony Davis F LeBron James F James Harden G Stephen Curry G
1 2014-15 2nd Pau Gasol C DeMarcus Cousins C LaMarcus Aldridge F Chris Paul G Russell Westbrook G
2 2014-15 3rd DeAndre Jordan C Tim Duncan F Blake Griffin F Kyrie Irving G Klay Thompson G
3 NaN NaN NaN NaN NaN NaN NaN
4 2013-14 1st Joakim Noah C LeBron James F Kevin Durant F James Harden G Chris Paul G
5 2013-14 2nd Dwight Howard C Blake Griffin F Kevin Love F Stephen Curry G Tony Parker G
6 2013-14 3rd Al Jefferson C LaMarcus Aldridge F Paul George F Damian Lillard G Goran Dragic G
7 NaN NaN NaN NaN NaN NaN NaN
8 2012-13 1st Tim Duncan C LeBron James F Kevin Durant F Kobe Bryant G Chris Paul G
9 2012-13 2nd Marc Gasol C Blake Griffin F Carmelo Anthony F Russell Westbrook G Tony Parker G
10 2012-13 3rd Dwight Howard C David Lee F Paul George F James Harden G Dwyane Wade G
11 NaN NaN NaN NaN NaN NaN NaN
12 2011-12 1st Dwight Howard C LeBron James F Kevin Durant F Kobe Bryant G Chris Paul G
13 2011-12 2nd Andrew Bynum C Kevin Love F Blake Griffin F Russell Westbrook G Tony Parker G
14 2011-12 3rd Tyson Chandler C Carmelo Anthony F Dirk Nowitzki F Dwyane Wade G Rajon Rondo G
15 NaN NaN NaN NaN NaN NaN NaN
16 2010-11 1st Dwight Howard C Kevin Durant F LeBron James F Kobe Bryant G Derrick Rose G
17 2010-11 2nd Amar'e Stoudemire C Pau Gasol F Dirk Nowitzki F Dwyane Wade G Russell Westbrook G
18 2010-11 3rd Al Horford C LaMarcus Aldridge F Zach Randolph F Manu Ginobili G Chris Paul G
19 NaN NaN NaN NaN NaN NaN NaN
20 2009-10 1st Dwight Howard C LeBron James F Kevin Durant F Kobe Bryant G Dwyane Wade G
21 2009-10 2nd Amar'e Stoudemire C Carmelo Anthony F Dirk Nowitzki F Steve Nash G Deron Williams G
22 2009-10 3rd Andrew Bogut C Tim Duncan F Pau Gasol F Brandon Roy G Joe Johnson G
23 NaN NaN NaN NaN NaN NaN NaN
24 2008-09 1st Dwight Howard C LeBron James F Dirk Nowitzki F Dwyane Wade G Kobe Bryant G
25 2008-09 2nd Yao Ming C Tim Duncan F Paul Pierce F Chris Paul G Brandon Roy G
26 2008-09 3rd Shaquille O'Neal C Carmelo Anthony F Pau Gasol F Tony Parker G Chauncey Billups G
27 NaN NaN NaN NaN NaN NaN NaN
28 2007-08 1st Dwight Howard C Kevin Garnett F LeBron James F Chris Paul G Kobe Bryant G
29 2007-08 2nd Amar'e Stoudemire C Tim Duncan F Dirk Nowitzki F Steve Nash G Deron Williams G
... ... ... ... ... ... ... ...
76 1995-96 1st David Robinson C Scottie Pippen F Karl Malone F Anfernee Hardaway G Michael Jordan G
77 1995-96 2nd Hakeem Olajuwon C Grant Hill F Shawn Kemp F John Stockton G Gary Payton G
78 1995-96 3rd Shaquille O'Neal C Charles Barkley F Juwan Howard F Reggie Miller G Mitch Richmond G
79 NaN NaN NaN NaN NaN NaN NaN
80 1994-95 1st David Robinson C Scottie Pippen F Karl Malone F John Stockton G Anfernee Hardaway G
81 1994-95 2nd Shaquille O'Neal C Shawn Kemp F Charles Barkley F Gary Payton G Mitch Richmond G
82 1994-95 3rd Hakeem Olajuwon C Detlef Schrempf F Dennis Rodman F Reggie Miller G Clyde Drexler G
83 NaN NaN NaN NaN NaN NaN NaN
84 1993-94 1st Hakeem Olajuwon C Scottie Pippen F Karl Malone F Latrell Sprewell G John Stockton G
85 1993-94 2nd David Robinson C Charles Barkley F Shawn Kemp F Mitch Richmond G Kevin Johnson G
86 1993-94 3rd Shaquille O'Neal C Derrick Coleman F Dominique Wilkins F Gary Payton G Mark Price G
87 NaN NaN NaN NaN NaN NaN NaN
88 1992-93 1st Hakeem Olajuwon C Charles Barkley F Karl Malone F Michael Jordan G Mark Price G
89 1992-93 2nd Patrick Ewing C Dominique Wilkins F Larry Johnson F John Stockton G Joe Dumars G
90 1992-93 3rd David Robinson C Scottie Pippen F Derrick Coleman F Tim Hardaway G Drazen Petrovic G
91 NaN NaN NaN NaN NaN NaN NaN
92 1991-92 1st David Robinson C Chris Mullin F Karl Malone F Michael Jordan G Clyde Drexler G
93 1991-92 2nd Patrick Ewing C Scottie Pippen F Charles Barkley F John Stockton G Tim Hardaway G
94 1991-92 3rd Brad Daugherty C Dennis Rodman F Kevin Willis F Mark Price G Kevin Johnson G
95 NaN NaN NaN NaN NaN NaN NaN
96 1990-91 1st David Robinson C Karl Malone F Charles Barkley F Michael Jordan G Magic Johnson G
97 1990-91 2nd Patrick Ewing C Chris Mullin F Dominique Wilkins F Kevin Johnson G Clyde Drexler G
98 1990-91 3rd Hakeem Olajuwon C James Worthy F Bernard King F Joe Dumars G John Stockton G
99 NaN NaN NaN NaN NaN NaN NaN
100 1989-90 1st Patrick Ewing C Charles Barkley F Karl Malone F Magic Johnson G Michael Jordan G
101 1989-90 2nd Hakeem Olajuwon C Larry Bird F Tom Chambers F Kevin Johnson G John Stockton G
102 1989-90 3rd David Robinson C Chris Mullin F James Worthy F Clyde Drexler G Joe Dumars G
103 NaN NaN NaN NaN NaN NaN NaN
104 1988-89 1st Hakeem Olajuwon C Karl Malone F Charles Barkley F Magic Johnson G Michael Jordan G
105 1988-89 2nd Patrick Ewing C Chris Mullin F Tom Chambers F John Stockton G Kevin Johnson G

106 rows × 7 columns


In [9]:
# Combine all 'Player' columns into one and remove extra information at the end of the names such as C,F, and G
allnbaM = pd.melt(allnba, id_vars=['All-NBA Team'],value_vars=['Player1','Player2','Player3','Player4','Player5'],
                 value_name='Player')
allnbaM['Player'] = allnbaM['Player'].str.replace("(C|F|G)\s*$", "")
allnbaM['Player'] = allnbaM['Player'].str.strip()
allnbaM = allnbaM.drop('variable',1)
allnbaM.tail()


Out[9]:
All-NBA Team Player
525 2nd John Stockton
526 3rd Joe Dumars
527 NaN NaN
528 1st Michael Jordan
529 2nd Kevin Johnson

Players Drafted:

Having read the All-NBA teams from Basketball-Reference.com, we do the same with the draft data from RealGM.com. The data is on multiple pages so we develop a loop that will read every page based on its url's distinguishable ending. Afterward we us the pd.concat function to convert the lists returned by the loop into a DF.


In [38]:
# Code for reading players drafted in every first round of the nba draft since 1989
draft = []
for number in range (27): 
    Year = str(2015 - (number))
    url1 = 'http://basketball.realgm.com/nba/draft/past_drafts/' 
    thisdraft = pd.read_html(url1 + Year)[0]
    print('Number:', number)
    print('Type: ', type(thisdraft))
    print(thisdraft.head())
    draft.append(thisdraft)


Number: 0
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick              Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1  Karl-Anthony Towns  MIN          NaN   C   7-0  244   19    0   
1     2    D'Angelo Russell  LAL          NaN  SG   6-5  195   19    0   
2     3       Jahlil Okafor  PHL          NaN   C  6-11  275   19    0   
3     4  Kristaps Porzingis  NYK          NaN  FC   7-3  240   19    0   
4     5       Mario Hezonja  ORL          NaN  SG   6-8  218   20    0   

               Pre-Draft Team       Class                         Nationality  
0                    Kentucky        Fr *  United States / Dominican Republic  
1                  Ohio State        Fr *                       United States  
2                        Duke        Fr *                       United States  
3  Baloncesto Sevilla (Spain)  1995 DOB *                              Latvia  
4     FC Barcelona II (Spain)  1995 DOB *                             Croatia  
Number: 1
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick          Player Team Draft Trades Pos   HT   WT  Age  YOS  \
0     1  Andrew Wiggins  CLE          NaN   F  6-8  199   19    1   
1     2   Jabari Parker  MIL          NaN   F  6-8  240   19    1   
2     3     Joel Embiid  PHL          NaN   C  7-0  250   20    1   
3     4    Aaron Gordon  ORL          NaN   F  6-9  220   18    1   
4     5      Dante Exum  UTH          NaN  PG  6-6  190   18    1   

                                      Pre-Draft Team       Class  \
0                                             Kansas        Fr *   
1                                               Duke        Fr *   
2                                             Kansas        Fr *   
3                                            Arizona        Fr *   
4  Australian Institute of Sport (Australian Capi...  1995 DOB *   

     Nationality  
0         Canada  
1  United States  
2       Cameroon  
3  United States  
4      Australia  
Number: 2
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick           Player Team Draft Trades Pos   HT   WT  Age  YOS  \
0     1  Anthony Bennett  CLE          NaN  PF  6-8  245   20    2   
1     2   Victor Oladipo  ORL          NaN   G  6-4  210   21    2   
2     3      Otto Porter  WAS          NaN  SF  6-8  198   20    2   
3     4      Cody Zeller  CHA          NaN   F  7-0  240   20    2   
4     5         Alex Len  PHX          NaN   C  7-1  260   20    2   

  Pre-Draft Team Class    Nationality  
0           UNLV  Fr *         Canada  
1        Indiana  Jr *  United States  
2     Georgetown  So *  United States  
3        Indiana  So *  United States  
4       Maryland  So *        Ukraine  
Number: 3
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick                  Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1           Anthony Davis  NOP          NaN  PF  6-10  253   19    3   
1     2  Michael Kidd-Gilchrist  CHA          NaN  SF   6-7  232   18    3   
2     3            Bradley Beal  WAS          NaN  SG   6-5  207   19    3   
3     4            Dion Waiters  CLE          NaN  SG   6-4  225   20    3   
4     5         Thomas Robinson  SAC          NaN  PF  6-10  250   21    3   

  Pre-Draft Team Class    Nationality  
0       Kentucky  Fr *  United States  
1       Kentucky  Fr *  United States  
2        Florida  Fr *  United States  
3       Syracuse  So *  United States  
4         Kansas  Jr *  United States  
Number: 4
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick             Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1       Kyrie Irving  CLE          NaN   G   6-3  193   19    4   
1     2   Derrick Williams  MIN          NaN   F   6-8  240   20    4   
2     3        Enes Kanter  UTH          NaN   F  6-11  245   19    4   
3     4   Tristan Thompson  CLE          NaN   F  6-10  238   20    4   
4     5  Jonas Valanciunas  TOR          NaN   C   7-0  265   19    3   

               Pre-Draft Team       Class                Nationality  
0                        Duke        Fr *  United States / Australia  
1                     Arizona        So *              United States  
2                    Kentucky        Fr *       Switzerland / Turkey  
3                       Texas        Fr *                     Canada  
4  Lietuvos Rytas (Lithuania)  1992 DOB *                  Lithuania  
Number: 5
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick            Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1         John Wall  WAS          NaN  PG   6-4  195   19    5   
1     2       Evan Turner  PHL          NaN  GF   6-7  205   21    5   
2     3    Derrick Favors  NJN          NaN  FC  6-10  265   18    5   
3     4    Wesley Johnson  MIN          NaN  GF   6-7  215   22    5   
4     5  DeMarcus Cousins  SAC          NaN   C  6-11  270   19    5   

  Pre-Draft Team Class    Nationality  
0       Kentucky  Fr *  United States  
1     Ohio State  Jr *  United States  
2   Georgia Tech  Fr *  United States  
3       Syracuse  Jr *  United States  
4       Kentucky  Fr *  United States  
Number: 6
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick           Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1    Blake Griffin  LAC          NaN  PF  6-10  251   20    6   
1     2  Hasheem Thabeet  MEM          NaN   C   7-3  265   22    5   
2     3     James Harden  OKC          NaN  SG   6-5  220   19    6   
3     4     Tyreke Evans  SAC          NaN   G   6-6  220   19    6   
4     5      Ricky Rubio  MIN          NaN   G   6-4  194   18    4   

           Pre-Draft Team       Class    Nationality  
0                Oklahoma        So *  United States  
1             Connecticut        Jr *       Tanzania  
2           Arizona State        So *  United States  
3                 Memphis        Fr *  United States  
4  FIATC Joventut (Spain)  1990 DOB *          Spain  
Number: 7
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick             Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1       Derrick Rose  CHI          NaN  PG   6-3  190   19    7   
1     2    Michael Beasley  MIA          NaN  PF   6-9  235   19    7   
2     3          O.J. Mayo  MIN   MIN to MEM  SG   6-5  210   20    7   
3     4  Russell Westbrook  SEA          NaN   G   6-3  200   19    7   
4     5         Kevin Love  MEM   MEM to MIN  FC  6-10  243   19    7   

  Pre-Draft Team Class    Nationality  
0        Memphis  Fr *  United States  
1   Kansas State  Fr *  United States  
2            USC  Fr *  United States  
3           UCLA  So *  United States  
4           UCLA  Fr *  United States  
Number: 8
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick        Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1     Greg Oden  POR          NaN   C   7-0  273   19    6   
1     2  Kevin Durant  SEA          NaN  SF   6-9  240   18    8   
2     3    Al Horford  ATL          NaN  FC  6-10  245   21    8   
3     4   Mike Conley  MEM          NaN  PG   6-1  175   19    8   
4     5    Jeff Green  BOS   BOS to SEA   F   6-9  235   20    7   

  Pre-Draft Team Class                         Nationality  
0     Ohio State  Fr *                       United States  
1          Texas  Fr *                       United States  
2        Florida  Jr *  Dominican Republic / United States  
3     Ohio State  Fr *                       United States  
4     Georgetown  Jr *                       United States  
Number: 9
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick             Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1    Andrea Bargnani  TOR          NaN  PF   7-0  245   20    9   
1     2  LaMarcus Aldridge  CHI   CHI to POR  FC  6-11  260   20    9   
2     3      Adam Morrison  CHA          NaN  SF   6-8  198   21    4   
3     4       Tyrus Thomas  POR   POR to CHI   F  6-10  225   19    8   
4     5   Shelden Williams  ATL          NaN  PF   6-9  250   22    6   

                       Pre-Draft Team       Class    Nationality  
0  Universo De'Longhi Treviso (Italy)  1985 DOB *          Italy  
1                               Texas        So *  United States  
2                             Gonzaga        Jr *  United States  
3                                 LSU        Fr *  United States  
4                                Duke          Sr  United States  
Number: 10
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick           Player Team Draft Trades Pos   HT   WT  Age  YOS  \
0     1     Andrew Bogut  MIL          NaN   C  7-0  260   20   10   
1     2  Marvin Williams  ATL          NaN  SF  6-9  237   19   10   
2     3   Deron Williams  UTH          NaN  PG  6-3  200   21   10   
3     4       Chris Paul  NOP          NaN  PG  6-0  175   20   10   
4     5   Raymond Felton  CHA          NaN  PG  6-1  205   21   10   

   Pre-Draft Team Class    Nationality  
0            Utah  So *      Australia  
1  North Carolina  Fr *  United States  
2        Illinois  Jr *  United States  
3     Wake Forest  So *  United States  
4  North Carolina  Jr *  United States  
Number: 11
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick            Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1     Dwight Howard  ORL          NaN   C  6-11  265   18   11   
1     2      Emeka Okafor  CHA          NaN  FC  6-10  255   21   10   
2     3        Ben Gordon  CHI          NaN  SG   6-3  200   21   11   
3     4  Shaun Livingston  LAC          NaN   G   6-7  182   18   11   
4     5      Devin Harris  WAS   WAS to DAL   G   6-3  185   21   11   

                                  Pre-Draft Team       Class  \
0  Southwest Atlanta Christian Academy (Georgia)  1985 DOB *   
1                                    Connecticut        Jr *   
2                                    Connecticut        Jr *   
3          Peoria Central High School (Illinois)  1985 DOB *   
4                                      Wisconsin        Jr *   

               Nationality  
0            United States  
1            United States  
2  England / United States  
3            United States  
4            United States  
Number: 12
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick           Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1     LeBron James  CLE          NaN   F   6-8  250   18   12   
1     2    Darko Milicic  DET          NaN  FC   7-0  275   18   10   
2     3  Carmelo Anthony  DEN          NaN   F   6-8  240   19   12   
3     4       Chris Bosh  TOR          NaN  PF  6-11  235   19   12   
4     5      Dwyane Wade  MIA          NaN  SG   6-4  220   21   12   

                            Pre-Draft Team       Class    Nationality  
0  St. Vincent St. Mary High School (Ohio)  1984 DOB *  United States  
1              KK Vrsac Swisslion (Serbia)  1985 DOB *         Serbia  
2                                 Syracuse        Fr *  United States  
3                             Georgia Tech        Fr *  United States  
4                                Marquette        Jr *  United States  
Number: 13
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick                Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1              Yao Ming  HOU          NaN   C   7-6  310   21    9   
1     2          Jay Williams  CHI          NaN   G   6-2  195   20    2   
2     3         Mike Dunleavy  GOS          NaN  GF   6-9  230   21   13   
3     4           Drew Gooden  MEM          NaN  FC  6-10  250   20   13   
4     5  Nikoloz Tskitishvili  DEN          NaN   F   7-0  225   19    4   

                       Pre-Draft Team       Class    Nationality  
0           Shanghai Dongfang (China)    1980 DOB          China  
1                                Duke        Jr *  United States  
2                                Duke        Jr *  United States  
3                              Kansas        Jr *  United States  
4  Universo De'Longhi Treviso (Italy)  1983 DOB *        Georgia  
Number: 14
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick            Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1       Kwame Brown  WAS          NaN   C  6-11  290   19   12   
1     2    Tyson Chandler  LAC   LAC to CHI   C   7-1  240   18   14   
2     3         Pau Gasol  ATL   ATL to MEM  FC   7-0  250   20   14   
3     4        Eddy Curry  CHI          NaN   C   7-0  295   18   12   
4     5  Jason Richardson  GOS          NaN  GF   6-6  225   20   14   

                       Pre-Draft Team       Class    Nationality  
0             Glynn Academy (Georgia)  1982 DOB *  United States  
1  Dominguez High School (California)  1982 DOB *  United States  
2          FC Barcelona Lassa (Spain)  1980 DOB *          Spain  
3    Thornwood High School (Illinois)  1982 DOB *  United States  
4                      Michigan State        So *  United States  
Number: 15
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick          Player Team Draft Trades  Pos   HT   WT  Age  YOS  \
0     1   Kenyon Martin  NJN          NaN    F  6-9  240   22   15   
1     2  Stromile Swift  VAN          NaN  F-C  6-9  225   20    9   
2     3    Darius Miles  LAC          NaN    F  6-9  210   18    9   
3     4    Darnel Fizer  CHI          NaN    F  6-8  246   21    6   
4     5     Mike Miller  ORL          NaN   GF  6-8  218   20   15   

                                 Pre-Draft Team       Class    Nationality  
0                                    Cincinnati          Sr  United States  
1                                           LSU        So *  United States  
2  East St. Louis Senior High School (Illinois)  1981 DOB *  United States  
3                                    Iowa State        Jr *  United States  
4                                       Florida        So *  United States  
Number: 16
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick           Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1      Elton Brand  CHI          NaN  PF   6-9  254   20   16   
1     2    Steve Francis  VAN   VAN to HOU   G   6-3  195   22   10   
2     3      Baron Davis  CHA          NaN   G   6-3  215   20   13   
3     4       Lamar Odom  LAC          NaN  PF  6-10  230   19   15   
4     5  Jonathan Bender  TOR   TOR to IND   F  6-11  202   18    8   

                       Pre-Draft Team       Class    Nationality  
0                                Duke        So *  United States  
1                            Maryland        Jr *  United States  
2                                UCLA        So *  United States  
3                        Rhode Island        So *  United States  
4  Picayune High School (Mississippi)  1981 DOB *  United States  
Number: 17
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick              Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1  Michael Olowokandi  LAC          NaN   C   7-0  270   23    9   
1     2          Mike Bibby  VAN          NaN   G   6-2  195   20   14   
2     3       Raef LaFrentz  DEN          NaN   F  6-11  245   22   11   
3     4      Antawn Jamison  TOR   TOR to GOS   F   6-9  235   22   16   
4     5        Vince Carter  GOS   GOS to TOR  SF   6-6  220   21   17   

   Pre-Draft Team Class        Nationality  
0         Pacific    Sr  Nigeria / England  
1         Arizona  So *      United States  
2          Kansas    Sr      United States  
3  North Carolina  Jr *      United States  
4  North Carolina  Jr *      United States  
Number: 18
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick            Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1        Tim Duncan  SAN          NaN  FC  6-11  250   21   18   
1     2    Keith Van Horn  PHL   PHL to NJN   F  6-10  220   21   10   
2     3  Chauncey Billups  BOS          NaN   G   6-3  210   20   17   
3     4   Antonio Daniels  VAN          NaN   G   6-4  195   22   13   
4     5       Tony Battie  DEN          NaN  PF  6-11  230   21   15   

  Pre-Draft Team Class    Nationality  
0    Wake Forest    Sr  United States  
1           Utah    Sr  United States  
2       Colorado  So *  United States  
3  Bowling Green    Sr  United States  
4     Texas Tech  Jr *  United States  
Number: 19
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick               Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1        Allen Iverson  PHL          NaN   G   6-0  165   21   14   
1     2         Marcus Camby  TOR          NaN   C  6-11  240   22   17   
2     3  Shareef Abdur-Rahim  VAN          NaN   F   6-9  225   19   12   
3     4      Stephon Marbury  MIL   MIL to MIN   G   6-2  180   19   13   
4     5            Ray Allen  MIN   MIN to MIL  SG   6-5  205   20   18   

  Pre-Draft Team Class    Nationality  
0     Georgetown  So *  United States  
1  Massachusetts  Jr *  United States  
2     California  Fr *  United States  
3   Georgia Tech  Fr *  United States  
4    Connecticut  Jr *  United States  
Number: 20
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick            Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1         Joe Smith  GOS          NaN   F  6-10  225   19   16   
1     2   Antonio McDyess  LAC   LAC to DEN   F   6-9  245   20   16   
2     3  Jerry Stackhouse  PHL          NaN  SF   6-6  218   20   18   
3     4   Rasheed Wallace  WAS          NaN  FC  6-11  230   20   16   
4     5     Kevin Garnett  MIN          NaN  PF  6-11  240   19   20   

                       Pre-Draft Team       Class    Nationality  
0                            Maryland        So *  United States  
1                             Alabama        So *  United States  
2                      North Carolina        So *  United States  
3                      North Carolina        So *  United States  
4  Farragut Career Academy (Illinois)  1976 DOB *  United States  
Number: 21
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick            Player Team Draft Trades Pos   HT   WT  Age  YOS  \
0     1    Glenn Robinson  MIL          NaN  SF  6-7  225   21   11   
1     2        Jason Kidd  DAL          NaN  PG  6-4  210   21   19   
2     3        Grant Hill  DET          NaN  SF  6-8  225   21   19   
3     4  Donyell Marshall  MIN          NaN   F  6-9  245   21   15   
4     5      Juwan Howard  WAS          NaN  PF  6-9  240   21   19   

  Pre-Draft Team Class    Nationality  
0         Purdue  Jr *  United States  
1     California  So *  United States  
2           Duke    Sr  United States  
3    Connecticut  Jr *  United States  
4       Michigan  Jr *  United States  
Number: 22
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick          Player Team Draft Trades  Pos   HT   WT  Age  YOS  \
0     1    Chris Webber  ORL   ORL to GOS  F-C  6-9  245   20   15   
1     2   Shawn Bradley  PHL          NaN    C  7-6  235   21   12   
2     3  Penny Hardaway  GOS   GOS to ORL   PG  6-7  195   21   14   
3     4  Jamal Mashburn  DAL          NaN   SF  6-8  247   20   13   
4     5      J.R. Rider  MIN          NaN   SG  6-5  215   22    9   

  Pre-Draft Team Class              Nationality  
0       Michigan  So *            United States  
1  Brigham Young  Jr *  United States / Germany  
2        Memphis  Jr *            United States  
3       Kentucky  Jr *            United States  
4           UNLV    Sr            United States  
Number: 23
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick              Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1    Shaquille O'Neal  ORL          NaN   C   7-1  325   20   19   
1     2     Alonzo Mourning  CHA          NaN   C  6-10  240   22   16   
2     3  Christian Laettner  MIN          NaN  PF  6-11  245   22   13   
3     4         Jim Jackson  DAL          NaN  SG   6-6  220   21   14   
4     5      LaPhonso Ellis  DEN          NaN  PF   6-8  240   22   11   

  Pre-Draft Team Class    Nationality  
0            LSU  Jr *  United States  
1     Georgetown    Sr  United States  
2           Duke    Sr  United States  
3     Ohio State  Jr *  United States  
4     Notre Dame    Sr  United States  
Number: 24
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick           Player Team Draft Trades Pos   HT   WT  Age  YOS  \
0     1    Larry Johnson  CHA          NaN   F  6-6  250   22   10   
1     2   Kenny Anderson  NJN          NaN  PG  6-0  168   20   14   
2     3      Billy Owens  SAC   SAC to GOS  SF  6-8  220   22   11   
3     4  Dikembe Mutombo  DEN          NaN   C  7-2  260   25   18   
4     5      Steve Smith  MIA          NaN  SG  6-7  200   22   14   

   Pre-Draft Team Class                       Nationality  
0            UNLV    Sr                     United States  
1    Georgia Tech  So *                     United States  
2        Syracuse  Jr *                     United States  
3      Georgetown    Jr  Democratic Republic of the Congo  
4  Michigan State    Sr                     United States  
Number: 25
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick              Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1     Derrick Coleman  NJN          NaN  FC  6-10  230   23   15   
1     2         Gary Payton  SEA          NaN   G   6-4  180   21   17   
2     3  Mahmoud Abdul-Rauf  DEN          NaN  PG   6-0  162   21    9   
3     4        Dennis Scott  ORL          NaN  SF   6-8  229   21   12   
4     5        Kendall Gill  CHA          NaN  SG   6-5  195   22   15   

  Pre-Draft Team Class    Nationality  
0       Syracuse    Sr  United States  
1   Oregon State    Sr  United States  
2            LSU  So *  United States  
3   Georgia Tech  Jr *  United States  
4       Illinois    Sr  United States  
Number: 26
Type:  <class 'pandas.core.frame.DataFrame'>
   Pick          Player Team Draft Trades Pos    HT   WT  Age  YOS  \
0     1  Pervis Ellison  SAC          NaN   C   6-9  210   22   12   
1     2     Danny Ferry  LAC   LAC to CLE  PF  6-10  230   22   14   
2     3    Sean Elliott  SAN          NaN  SF   6-8  205   21   12   
3     4       Glen Rice  MIA          NaN  SF   6-8  228   22   15   
4     5       J.R. Reid  CHA          NaN  PF   6-9  247   21   11   

   Pre-Draft Team Class    Nationality  
0      Louisville    Sr  United States  
1            Duke    Sr  United States  
2         Arizona    Sr  United States  
3        Michigan    Sr  United States  
4  North Carolina  Jr *  United States  

In [10]:
# Code for placing all players drafted in the first round into a pandas dataframe
alldrafts = pd.concat(draft)
alldrafts = alldrafts.drop('Team',1)
alldrafts.drop(alldrafts.columns[[2]], axis=1, inplace=True)
alldrafts.loc[alldrafts.Class.str.contains("DOB"), "Class"] = "N/A"
alldrafts['Class'] = alldrafts['Class'].str.replace("*", "")
alldrafts['Class'] = alldrafts['Class'].str.strip()

alldrafts.tail(10)


Out[10]:
Pick Player Pos HT WT Age YOS Pre-Draft Team Class Nationality
17 18 B.J. Armstrong G 6-2 175 21 11 Iowa Sr United States
18 19 Kenny Payne F 6-8 195 22 4 Louisville Sr United States
19 20 Jeff Sanders F 6-8 225 23 5 Georgia Southern Sr United States
20 21 Blue Edwards SG 6-4 200 23 10 East Carolina Sr United States
21 22 Byron Irvin G 6-5 190 22 4 Missouri Sr United States
22 23 Roy Marble GF 6-6 190 22 3 Iowa Sr United States
23 24 Anthony Cook FC 6-9 205 22 5 Arizona Sr United States
24 25 John Morton G 6-3 180 22 6 Seton Hall Sr United States
25 26 Vlade Divac C 7-1 260 21 16 KK Partizan (Serbia) N/A Serbia
26 27 Kenny Battle SF 6-6 210 24 4 Illinois Sr United States

In [30]:
# Get means of draft positions based on college class
print('Avergage draft position for freshmen in the first round is:',
      alldrafts[alldrafts['Class'].str.contains('Fr')]['Pick'].mean())
print('Avergage draft position for Sophomores in the first round is:',
      alldrafts[alldrafts['Class'].str.contains('So')]['Pick'].mean())
print('Avergage draft position for Juniors in the first round is:',
      alldrafts[alldrafts['Class'].str.contains('Jr')]['Pick'].mean())
print('Avergage draft position for Seniors in the first round is:',
      alldrafts[alldrafts['Class'].str.contains('Sr')]['Pick'].mean())
print('Avergage draft position for those who didnt attend college in the first round is:',
      alldrafts[alldrafts['Class'].str.contains('N/A')]['Pick'].mean())


Avergage draft position for freshmen in the first round is: 11.202127659574469
Avergage draft position for Sophomores in the first round is: 12.453781512605042
Avergage draft position for Juniors in the first round is: 13.33108108108108
Avergage draft position for Seniors in the first round is: 17.15771812080537
Avergage draft position for those who didnt attend college in the first round is: 16.875

In [33]:
# Gives us the distribution of selections by class ordered by pick number
# But first we must reorder the classes by Fr, So, Jr, Sr, N/A
Classes = ['Fr', 'So', 'Jr', 'Sr', 'N/A']
mapping = {Class: i for i, Class in enumerate(Classes)}
key = alldrafts['Class'].map(mapping)
alldrafts_in_order = alldrafts.iloc[key.argsort()]

ax = sns.swarmplot(x="Class", y="Pick", data=alldrafts_in_order)
ax.set_title('Number of Draft Selections Per Class by Pick Number')
ax.set_ylim(0)


Out[33]:
(0, 35.0)

In [34]:
#code for number of players drafted in each class => Seniors are  most prevalent followed by juniors
clAss = ['Fr','So','Jr','Sr','N/A']
alldraftsC = alldrafts.copy()
grades = []
for x in  clAss:
    grades.append(x)
    alldraftsC[x] = alldraftsC['Class'].str.contains(x)*1
classes = alldraftsC[grades]
classes_counts = classes.sum()

print(classes_counts)

fig, ax = plt.subplots()
classes_counts.plot(ax=ax, legend=False, kind = 'bar', color=['blue','green','red','turquoise','purple'])
ax.set_xlabel("Player's Class")
ax.set_ylabel('Number of Players Drafted')
ax.set_title('Players Drafted by College Class')


Fr      94
So     119
Jr     148
Sr     298
N/A    120
dtype: int64
Out[34]:
<matplotlib.text.Text at 0x1123ad320>

Merge both data tables:


In [25]:
# Merge on Player (Add an 'All-NBA Team' column)
draftallnba = pd.merge(alldrafts, allnbaM,   
                 how='left',         
                 on='Player')
draftallnba.tail(30)


Out[25]:
Pick Player Pos HT WT Age YOS Pre-Draft Team Class Nationality All-NBA Team
939 4 Glen Rice SF 6-8 228 22 15 Michigan Sr United States 2nd
940 5 J.R. Reid PF 6-9 247 21 11 North Carolina Jr United States NaN
941 6 Stacey King PF 6-11 250 22 10 Oklahoma Sr United States NaN
942 7 George McCloud SF 6-6 205 22 13 Florida State Sr United States NaN
943 8 Randy White PF 6-8 240 21 6 Louisiana Tech Sr United States NaN
944 9 Tom Hammonds PF 6-9 215 22 13 Georgia Tech Sr United States NaN
945 10 Pooh Richardson PG 6-1 180 23 11 UCLA Sr United States NaN
946 11 Nick Anderson GF 6-6 228 21 14 Illinois So United States NaN
947 12 Mookie Blaylock PG 6-1 190 22 13 Oklahoma Sr United States NaN
948 13 Michael Smith F 6-10 225 24 5 Brigham Young Sr United States NaN
949 14 Tim Hardaway PG 6-0 175 22 14 UTEP Sr United States 2nd
950 14 Tim Hardaway PG 6-0 175 22 14 UTEP Sr United States 3rd
951 14 Tim Hardaway PG 6-0 175 22 14 UTEP Sr United States 2nd
952 14 Tim Hardaway PG 6-0 175 22 14 UTEP Sr United States 1st
953 14 Tim Hardaway PG 6-0 175 22 14 UTEP Sr United States 2nd
954 15 Todd Lichti G 6-4 205 22 5 Stanford Sr United States NaN
955 16 Dana Barros PG 5-11 165 22 14 Boston College Sr United States NaN
956 17 Shawn Kemp C 6-10 280 19 14 Trinity Valley CC Fr United States 2nd
957 17 Shawn Kemp C 6-10 280 19 14 Trinity Valley CC Fr United States 2nd
958 17 Shawn Kemp C 6-10 280 19 14 Trinity Valley CC Fr United States 2nd
959 18 B.J. Armstrong G 6-2 175 21 11 Iowa Sr United States NaN
960 19 Kenny Payne F 6-8 195 22 4 Louisville Sr United States NaN
961 20 Jeff Sanders F 6-8 225 23 5 Georgia Southern Sr United States NaN
962 21 Blue Edwards SG 6-4 200 23 10 East Carolina Sr United States NaN
963 22 Byron Irvin G 6-5 190 22 4 Missouri Sr United States NaN
964 23 Roy Marble GF 6-6 190 22 3 Iowa Sr United States NaN
965 24 Anthony Cook FC 6-9 205 22 5 Arizona Sr United States NaN
966 25 John Morton G 6-3 180 22 6 Seton Hall Sr United States NaN
967 26 Vlade Divac C 7-1 260 21 16 KK Partizan (Serbia) N/A Serbia NaN
968 27 Kenny Battle SF 6-6 210 24 4 Illinois Sr United States NaN

In [26]:
# Count the number of All-NBA selections by time spent in college
counts = draftallnba['All-NBA Team'].groupby([draftallnba['Class'], draftallnba['All-NBA Team']]).count()
counts = pd.DataFrame(counts)
counts.columns = ['Number of Selections']
counts = counts.unstack(level=0)
counts = counts['Number of Selections']
counts = counts[['Fr', 'So', 'Jr', 'Sr', 'N/A']]
countsT = counts.T
countsT['Total'] = [24,51,45,56,87]
counts = countsT.transpose()
counts


Out[26]:
Class Fr So Jr Sr N/A
All-NBA Team
1st 7 15 12 19 36
2nd 9 19 12 23 30
3rd 8 17 21 14 21
Total 24 51 45 56 87

In [28]:
# Plot All-NBA selections by time spent in college
fig, ax = plt.subplots()
counts.plot(ax=ax, legend=True, kind = 'barh')
ax.set_xlabel('Number of All-NBA Selections')
ax.set_title('All-NBA Selections by College Class')


Out[28]:
<matplotlib.text.Text at 0x112123828>

Ultimately, while the results show us that freshmen are drafted with higher priority picks than the rest, closely followed by sophomores, seniors are the most commonly drafted players in the first round. Nevertheless, it is those who decided to jump straight to the NBA from high school or who played a year or more abroad before joining the NBA that have garnered the highest amount of All-NBA honors.


In [ ]: