Data Web Scraping NBA Stats

Posted on Dec 13, 2017
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.


This is my second project. A project focused on web scraping and producing data models and insights to viewers that they would not typically see or be able to extract from certain data upon first observation. I am passionate about sports and thought connecting data science to sports in this project would be very intriguing.

The technology industry has taken over every realm of society it seems like with little opposition. From the way people entertain ourselves with our smart phones and social media all the way to how business operate and how they sell and market their products and respective brands. It seems hand in hand with this takeover, Data Science has seen a profound boom in its prominence in its use and application today due to the benefits and new realizations that people have come to see through the various new models and new statistics formed by machine learning programs as well as analytics.


For this reason alone, sports has seen a dramatic increase in the use of analytics and various algorithms and programs too see what factors not looked at before can increase a teams chance of winning as well as the organization's chance at future success. I personally, am a avid sports fan who takes every chance he can get to discuss and learn more about people's favorite teams as well as their philosophies and opinions on what they think is most important or crucial in creating a successful team in any sport.

In this project I focused on basketball and tried to find new little statistics that could be seen through their prevalence on successful teams as a factor crucial in order to win and be successful.Through scraping nba statistics from from last season and engineering the data, I attempted to find new and improved ways that analytically can be shown to be crucial to winning championships and are apparent on top tier teams such as the Cavaliers and Warriors.


I did this by creating a scraper that scraped for NBA statistics from last season. The categories I scraped were each teams Average 4th Quarter margin, Each teams average points from 3-pt FGs per game, each teams average Points in the Paint per Game, as well as each teams total points resulting from fast break opportunities. Upon scraping, the resulting csv files show for the 4 categories: each teams rank compared to the rest of the league, their average of that statistic for the season, the respective statistic from the previous game, average of that statistic over the last 3 games, as well as their averages both on the road as well as at home.

This is what the resulting csv file for total points in the paint per game:

I believe these statistics are some of the most important and crucial to success in basketball and hopefully some of my statistics, models and graphs can strengthen my assertion.

Home and Away Averages

This graph shows the home and away averages for 4th quarter margins of each team.
Data Web Scraping NBA Stats

Unfortunately for me in wanting some results with strong correlations, none can strongly be made in terms of winning the 4th quarter resulting in championships. 7 of the top 10 teams in this category did make the playoffs with the champion Warriors coming in at 6, but their opponent in last years finals, the Cavaliers were 27th out of 30 teams in the category but seemed to be doing just fine in coasting to their 3rd straight finals appearance.

For one that is familiar with basketball, know from the perspective that basketball is a game of 4 quarters, good teams may already have handled lesser competition in 3 quarters by more than 20 points for example and are not affected by their losing margin in the 4th because it does not pose any significance to the end outcome of the game. In terms of further research one could look to see games that go into the fourth quarter with a team trailing by 5 or less points as a more effective way of analyzing performance in the 4th because that involves the clutch factor.

Fast Break Points

When looking at FastBreak Points per game I thought it would be interesting to see teams change in averages from the 2015 season to the 2016 season.

Here the chart shows each teams averages side by side:


17 teams improved from the season before while 13 did not. Of the 3 of the final 4 teams from the NBA 2016 Season (Cavs, Warriors, Spurs, Celtics) only the Celtics decreased in their average fast break points per game. Both six seeds (OKC and Bucks) and seven seeds(Pacers and Griz) from each conference decreased in their averages from the previous season along with one 5 seed (Hawks), 3 seed(Rockets), and 4 seed(Wizards).

None of these teams looking at statistics as well as the overall eye test had a chance at winning the championship last season and does show the increasing value and importance of teams improving their fast break scoring. The champion Warriors have led the statistics the past 3 seasons, and barring the 3-1 collapse, have produced 3 championship seasons.

Further research wise when looking at this project from a big picture is that data science will always prove beneficial and vital in improving quality of teams and athlete's performance in regards to sports. And it will only grow because even through simple models such as these one can see that the 4th Quarter margin does not mean as much as the amount of fast break points a team is producing per game.

Little things like this and the little edge that teams, coaches, scouts, and executives are all looking for and crave can and will all be produced through data science. With it providing a constantly new and innovative way to look at what was perceived in the past as bland and concrete statistics in a more complex and alternative way.

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI