Tag: sabermetrics

Blogging with Flask

Right before the NBA season began, I laid out my predictions for how many wins each team would achieve this season. To track the progress of these predictions as well as the overall NBA rankings, I planned to blog on a weekly basis. While I could have gone with a standard WordPress blog (like this one) I wanted to easily run and access Python code. To do that, I created a blog with Flask: MNBA.

Flask is “is a microframework for Python”. It is my favorite way to integrate Python into a website. The tutorial they offer, Flaskr, is the creation of a mini-blog. So setting up the foundations of my website MNBA was essentially an adaptation of that tutorial. For the hosting of my site I use PythonAnywhere.com, which is cheap and they do a great job of hosting Flask-based websites. The layout was a publicly available template using the Pure.css style.

I have a Python script that runs each week to pull current data about NBA teams (such as wins, losses, points scored, and points allowed), runs some simple calculations (to get my desired statistics such as Pythogrean wins expected) and writes this data to a MySQL database. Then I use Matplotlib to graph recent changes in expected wins. I do a short writeup of my thoughts on whatever is going on in the NBA as well as a table view of the MySQL data for that week.

I have created a few other Flask sites I plan to write about in the future. While there was a bit of a learning curve because it is different from a simple Python script on your computer, after some experience with Flask it is easy to get a new site up and running.

What I do with Python

Over the past year I have become an everyday user of the programming language Python. I use it both at work and for personal projects. At work, I’m responsible for marketing analytics and primarily deal with the Salesforce database and Salesforce’s marketing automation platform Pardot. I use Python to solve problems not possible out of the box. Outside of work, I mainly use Python to analyze spots statistics.

I am not an expert programmer but I have programmed on and off for over a decade. I find Python easy to use, adept at data manipulation, and effective for accessing APIs. APIs are methods for communicating with particular services of products. For example, I built a tool at work that uses APIs to get data from accounts on Youtube, Google Analytics, Facebook, Twitter, and Pardot on a regular basis.

I first learned the basics of Python for free on Codecademy and then learned more by completing the Data Science with Python track on DataCamp, which cost me something like $60. The Codecademy course was a fine introduction although it wasn’t enough knowledge to do any projects truly on your own. More difficult for me than learning the actual Python language was learning how to set up a working environment. For most projects I now use Thonny, which I highly recommend to other beginners. For web apps and scripts that run daily, I use pythonanywhere.

While the Data Camp course involved lots of applied learning, taking on projects at work and for fun that use Python was what really solidified my knowledge. Here is a list of projects I have completed with Python:

I’m planning to keep blogging weekly to dive deeper into each of the projects and the various tools I have used along the way.

Navigation