The NBA letting you get closer to the game

11 August 2015
No there hasn’t been a sudden change in ticket prices that is going to allow you to sit courtside (especially hard when you live in London as the NBA would have to partner with BA to drop flight prices as well). So what have they done to make me write this blog post?Quite simply this:Stats NBA comGreat – another table of data – big woop. Lend me one more minute and then you can go and click on espn.com or grantland.com to go and see how the pro’s do this.The NBA have opened a whole new set of statistics that allow you to monitor game, assess player performance and spot trends that were previously just gut instinct. This all stems from the ingenious SportsVu ([insert link to SportsVu]) that has revolutionalised not only how the game has been measured but is revolutionising how the game is coached.As this data is in a webpage, it’s actually held in an underlying page that we can access. Using the ‘Inspect Element’ option on your browsers right-click menu, then you can find the source of the pages information. For example, our page we need to get to is:NBA Alteryx 1st URLUsing just Alteryx and Tableau, I have created a package that allows me to pull back statistics from the Playoffs, re-run them when I want to and start analysing in minutes. Now I can access the distance every defender was from their shooter and whether they successfully altered the shot or not. Want to know how? Then follow these steps:The Alteryx bit…What I need to achieve:
  • Find out how to scroll through URLs that hold the information for each player
  • Find a way to identify the ‘Player IDs’ that will prevent me from having to scroll through a load of URLs until I hit one that pulls back data for each player
  • Scrape that information in to a flat file
  • Transform that information in to a format that it can be read in Tableau (phew that sounds like a fair bit of work – not in Alteryx it isn’t)
NBA Alteryx - find player full macroThis is the final outcome so let’s below are the considerations for each part of the moduleStep 1 – Analyse the URL to find what is needed to build the URL that will return the data we wantHere it is:NBA Alteryx 2nd URLSo what do I need to think about in that lot of characters – quite simply – the six digits after ‘PlayerID’.Step 2 – How do we find that PlayerID so we can insert it in to URL?Well I could generate a number and insert it but where do I start and stop? Also, I’m going to want to run this module frequently so I don’t really want to run the module for hours at a time. So why not try and find the PlayerIDs elsewhere?Well in the Team Roster page all the Players are listed and if you hover over each of their names, a URL pops in the bottom-right hand corner of the screen. So how do you grab that in Alteryx?If it is on the screen somewhere then it is being populated at somepoint of the process so open up ‘Inspect Element’ on your browser and refresh the page. Here is the link that I found that holds the PlayerIDs:NBA Alteryx 3rd URLHere’s what the data looks like on this page:Team PlayerID xmlWell that’s not quite ready to be used just yet so we have some parse out the data which is scarily easy in Alteryx.NBA Alteryx - find playerIDTools used:Download tool – goes to the web and pulls back the data from the JSON pageJSON – forms ‘JSON_Name’ and ‘JSON_ValueString’Text to Columns – Breaks the JSON_Name field in to it’s component parts so we can get access to the measure names we wantSelect and Filter Tools – cutting out some of the junk data points formed as part of the ‘Text to Columns’ toolCrosstab – To get PlayerID to be in a different column from the Player’s Name.Select – Renaming the fields created in the Crosstab tool to ‘PlayerID’ and ‘Player Name’All you need to do now is to collect the URLs for each team (yes I could have built a module for that too but the teams aren’t changing anytime soon so I thought 30 static URLs on a spreadsheet was easy enough). Feed the URLs in at the start of this process and bingo – you now have PlayerIDs for every player currently with a team.I’ve got the PlayerIDs – now what?Once you have the PlayerIDs now you can enter those six digits in to the original URL we found earlier. Obviously we do that in Alteryx (OBVIOUSLY!).NBA Alteryx - find player statsNote the line flowing down from above – that’s right all the steps are one workflow so with one click I can refresh an awesome set of data!The process to make this data ready for Tableau is very similar to the PlayerID finder part of the workflow – you just have more columns to control hence the few extra Select, Filter and Formula tools. If you have made it this far in the process then you will see why I have added Browse Tools to all the outputs as there is a lot to clean-up.I have Alteryx outputting to a .csv file that I can connect Tableau to so I can also use the data elsewhere but bonus points to you if you just want to output to a Tableau Data Extract (.tde file) so you will get better performance when analysing the data in Tableau.The Tableau bit…What I need to achieve:
  • Freaking awesome visualisations
  • Using new metrics that I haven’t had access to in box scores previously (like distance from defender etc)
There really is so much great data here to answer some pretty interesting questions:
  1. Which team are creating the most space between their defenders and themselves when shooting?
  2. Who in the league is dribbling more than others before their shot and does that increase their shooting percentage?
  3. Are defenders being closer to the shoot when nearer the basket a greater inhibitor to the shooter than at the 3-point line?
Well I have hours of fun to play with this data still so I won’t steal all the fun away from you. I have produced a few visualisations to show what I have started to investigate but there is definitely more to come. I would love to see what you come up with as well so let me know how you get on and share your work on Tableau Public.Distance from basket for FGMShot Profile of each team- X axis distance from basket and size of line is % of shots from that distanceClosest DefenderClosest defender by each shot type by Field Goal Made %
Author:
Carl Allchin
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Information Lab and data industry
Subscribe now
© 2025 The Information Lab