<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aaron Smith on Medium]]></title>
        <description><![CDATA[Stories by Aaron Smith on Medium]]></description>
        <link>https://medium.com/@aaroncolesmith?source=rss-faeed41249e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Dhhkvrfov37lXpZqeoGUKw.jpeg</url>
            <title>Stories by Aaron Smith on Medium</title>
            <link>https://medium.com/@aaroncolesmith?source=rss-faeed41249e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:34:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aaroncolesmith/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create a free, always up to date data app using Deepnote, Streamlit & GitHub]]></title>
            <link>https://medium.com/@aaroncolesmith/how-to-create-a-free-always-up-to-date-data-app-using-deepnote-streamlit-github-d3b302d9824c?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3b302d9824c</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Mon, 21 Feb 2022 15:49:06 GMT</pubDate>
            <atom:updated>2022-02-22T14:40:42.621Z</atom:updated>
            <content:encoded><![CDATA[<p>I wanted to write a quick article and tutorial about a free and easy way to build data apps. To me a data app is a web app that allows you to visualize and explore a given dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*WNB7GpVZ1zXprM9JmG3ZpQ.gif" /><figcaption>Example of a Data App I built to visualize some FiveThirtyEight odds over time</figcaption></figure><p>A couple of quick caveats and notes that informed my direction:</p><ul><li>I’m not a web developer — I’m a Product Manager and have worked extensively with data, both professionally and as passion projects</li><li>I wanted to use free resources — both because I’m frugal and because this would allow anyone to be able to emulate my setup</li><li>I wanted to be able to have an automatically updating dataset that could be visualized over time — I’ve built a lot of these with a manual push of a button to update the data, but I wanted these to be hands off.</li></ul><p>First, I mapped out how I would solve this problem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BJPK6Yj9kmwef4Dj" /><figcaption>I love drawing things out on whiteboards</figcaption></figure><p>We’d have 4 main pieces that would act together:</p><ul><li><strong>Data Source</strong> — somewhere that has an interesting bit of data that I want to save off for visualization</li><li><strong>Data Bot</strong> — code that could go out and run on a given interval to grab data and send it to a data storage</li><li><strong>Data Storage</strong> — somewhere that I can store off the data</li><li><strong>Data App / Viz</strong> — something that can take what I’ve done and put it on the web for data visualization and exploration</li></ul><p>Why not just use the data source? In an ideal world, I would be able to hit a publicly available API to get whatever I need, but due to storage costs and a variety of other factors, that isn’t always available. For example, if I wanted to see how betting odds for the Super Bowl trend over time, the sportsbook will only have the most recent odds, not the total odds. So I have to go out on a given interval, check the value and save it off.</p><p>Let’s start w/ the Data Source. Use your imagination here, but this can be any interesting bit of data. This could be a sportsbook to see gambling odds over time, a shopping page to see the price of an item over time, a crypto market so you can see the price of your favorite cryptocurrency over time — whatever is interesting to you!</p><p>For this example, I’ll use FiveThirtyEight which is a website that provides really cool statistics about politics and sports — specifically, I’m going to look at Global Club Soccer Rankings. This is a data source that will update over time as teams progress throughout the season, so it will be cool to see it over time.</p><p>Ideally, this data can be referenced programmatically via API or by hijacking API calls, but that isn’t always the case, so I will work you through a quick example of web scraping.</p><p>This will also cover the first two pieces in our puzzle referenced earlier:</p><ul><li>Data Source — FiveThirtyEight’s web page on <a href="https://projects.fivethirtyeight.com/soccer-predictions/global-club-rankings/">Global Club Soccer Rankings</a></li><li>Data Bot — here I’ll use <a href="https://deepnote.com/referral?token=a8cf69ac">Deepnote</a> (feel free to use that referral link to sign up if you haven’t). If you are familiar with Jupyter or Google Colab notebooks, Deepnote will be no problem for you. Deepnote is basically just a cloud data science notebook. I like it because I can reference and run my code from any machine and I can even schedule notebooks to run hourly or daily to automatically update my data</li></ul><p>So getting a bit deeper into Deepnote (pun intended), let’s create a project and get to building our Data Bot.</p><p>In the first cell, let’s import 5 Python packages — the first few will help us with scraping and manipulating data and the last one will help us push data to our Data Storage.</p><pre>import pandas as pd</pre><pre>import requests</pre><pre>from bs4 import BeautifulSoup</pre><pre>import datetime</pre><pre>import os</pre><p>Ok, if you go ahead and run that, you’ll notice it fails, but Deepnote provides some handy suggestions to resolve common failures. In this case, we’ll need to install BeatifulSoup, our web scraping library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bX1RC3xREXXtV-Ri" /><figcaption>If you haven’t installed BeautifulSoup in your Deepnote environment, you’ll need to</figcaption></figure><p>Go ahead and install that and then click to follow Deepnote’s suggestion to move BeatifulSoup to our requirements.txt — this means we won’t have to reinstall this package every time. Thanks Deepnote!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XKS59__YSPqzhUBD" /><figcaption>Nice helpful error management from Deepnote!</figcaption></figure><p>Now we should be able to import all the packages successfully. So we can start web scraping!</p><p>It starts with just three lines and the only modification that needs to be done is to provide the URL of your Data Source. The rest of this code will pull that web page and load it into our scraping library.</p><pre>url = ‘https://projects.fivethirtyeight.com/soccer-predictions/global-club-rankings/&#39;</pre><pre>req = requests.get(url)</pre><pre>soup = BeautifulSoup(req.content, ‘html.parser’)</pre><p>I’m not going to go too in depth into web scraping — there are plenty of other articles that will do that better than I can. But I’ll go over what elements are necessary for my data app. I basically just need to pull these two columns from the table on my Data Source — Team &amp; Team Rating (SPI).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*L-dtaHvD4nT0GNK4" /><figcaption>We’ll need to scrape the TEAM and TEAM RATING — SPI columns</figcaption></figure><p>To do that, I’ll need to inspect the web element and figure out how it is referenced so we can pull that information.</p><p>Looking at the web element, I can see that our table is made up of rows (&lt;tr&gt;) and the row is made up of cells (&lt;td&gt;), a couple of those cells contain our relevant data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ejF-vbI-Tu7aJrRb" /><figcaption>Inspecting web element — the key to web scraping success</figcaption></figure><p>BeautifulSoup provides some wonderful tools to analyze the data that you’ve scraped. To start, lets pull back all rows from the page we scraped</p><pre>soup.findAll(‘tr’)</pre><p>Looking at the results, you can see that the first couple of rows coming back are not relevant, but the rest look like the data we are after. And a nice bonus is that we are also getting hidden rows that are by default hidden from the UI, so we’ll have a nice sized dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rkHcxPnRBVUP4ZWH" /><figcaption>The results of finding all rows (&lt;tr&gt;) from the page we scraped</figcaption></figure><p>So, we will need to store this result as a list and we’ll iterate through the list. In each iteration, we’ll need to validate whether the row is invalid (does not contain Global Club Soccer Rankings data) or valid (contains relevant data). If the row is valid, we’ll need to pull out the Club Name and the Team Rating (SPI).</p><pre>rows = soup.findAll(‘tr’)</pre><p>Just looking at the results, we can try filtering our list to only look at rows that contain “num ranking” to pull back our valid Global Club Soccer Rankings data.</p><p>Within each row, you can scan the cells to find the class associated with the data that we are interested in. To play around with this, we can set one row to the 5th row in the list (so we are avoiding the first ones that aren’t relevant).</p><pre>row=rows[4]</pre><p>To find the data in a cell, we’ll need to use BeatifulSoup again to find the a cell based on class — we can use .text to pull out the display value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/0*NjGurBBKw6C6oDxQ" /><figcaption>For each row, identifying the data we need to store</figcaption></figure><p>So it looks like the Team worked correctly, but the Rating came back 3, when we were expecting 92.6.</p><p>It turns out, multiple cells have a class that starts with num, so we are going to have to select the last one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*9kQtjHJHERJ4PubL" /><figcaption>Need to find a slight workaround for the multiple cells with a similarly named class</figcaption></figure><p>Ok, now that we have figured out how to pull the Team Name and Rating for one row, we can build a loop to go through all rows. We are going to store the results in two lists and then combine them together in a dataframe to have a nice table at the end with our results.</p><p>I’m also going to add the current timestamp — I do this so that I can see the data over time, so it’s important to store the timestamp next to the relevant data.</p><p>We are also going to do a check on each row to see if that row includes the string ‘num ranking’ so that we aren’t including rows that don’t have relevant data.</p><p>The result should be a nice clean table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pDBDPnxI_-2Jarbd" /><figcaption>Things are starting to take shape!</figcaption></figure><p>At this point, most of the Data Bot portion of the project is complete. So next, we will setup our GitHub repo so that we can connect our Data Bot to our Data Source and start to build out the Data App.</p><p>Ok, so go ahead and create a new GitHub repository, follow GitHub’s setup guidance and make note of the repo url — we are going to head back to Deepnote and start to push updates to this GitHub repo from our Data Bot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6IaMpzPkA_dA-1G-" /><figcaption>Moving on to our GitHub repository</figcaption></figure><p>Now there are a few parts of the upcoming portion that I’m assuming have been setup — if not, here are some guides:</p><ul><li>Personal access token authentication for GitHub: <a href="https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/">https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/</a></li><li>Deepnote Environment Variables: <a href="https://docs.deepnote.com/environment/environment-variables">https://docs.deepnote.com/environment/environment-variables</a></li></ul><p>You’ll need these setup so that you can securely store your GitHub credentials to push your data to your repository.</p><p>So now we need to clone our GitHub repository into our Deepnote environment, save the Global Club Soccer Rankings data, and push the results back up to GitHub. We will only need to do this for the first time, but afterwards we’ll need to setup some logic to run this process each time our Data Bot runs.</p><p>So, we’ll need to setup our config w/ the email associated to our GitHub account, clone the repository, change directory to our newly pulled directory and then save our data to that directory.</p><p>You can do a quick check and see the csv now in your directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VkbKa8W4jVJxLU6X" /><figcaption>Getting our GitHub repository into our Deepnote Data Bot</figcaption></figure><p>Ok, now that we have our data in our repository, we need to push it back to GitHub.</p><p>To do this, we’ll want to reference our Environment Variable that we are securely storing for our GitHub Access Token. I’m also going to run the <em>%%capture</em> IPython magic command to suppress the output so that anyone visiting my notebook doesn’t see my secure values in the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nm5LXBO9Mc--zHW8" /><figcaption>Pushing data back to our GitHub repository</figcaption></figure><p>If everything worked correctly, you should now see your data file in your GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Uw4fFCE-mcNQKU_h" /><figcaption>Success — our data is now in the GitHub repository</figcaption></figure><p>Now we need to slightly modify that logic to account for subsequent runs of our Data Bot to follow these steps:</p><ul><li>Remove the directory we had previously pushed to our GitHub repository</li><li>Clone a fresh version of our GitHub repository</li><li>Combine our newly pulled data with existing data from our GitHub repository</li><li>Push the results back up</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZnztCseFIaSBTFEr" /><figcaption>Updating our previous Data Bot &gt; Data Storage logic to account for subsequent runs</figcaption></figure><p>Assuming that runs successfully, the Data Bot is now complete. You could manually run that entire notebook and it’ll get the most recent data and push it up to your GitHub repository. Even better, you can schedule it to run automatically with Deepnote.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*k0tz5_GRfqmVvsXT" /><figcaption>Schedule the Data Bot to run automatically</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2Sbx9iUqOUKTHJHv" /><figcaption>Depending on your use case, set your Schedule accordingly. It’s also nice to get failure notifications via email</figcaption></figure><p>Depending on your use case, it may make sense to run Hourly, Daily or Weekly. It would also be beneficial to do some data checks and only upload data if there has been a change so you aren’t wasting GitHub storage space.</p><p>I have previously used the Updated value in the page and will just not upload data if that date is less than or equal to the latest date in my existing file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tF9GUkIUveAp75Z8" /><figcaption>FiveThirtyEight has a nice last updated value that can be referenced to avoid uploading redundant data</figcaption></figure><p>At this point, our Data Bot is complete and its scheduled to update our Data Storage on a scheduled cadence. So all that is left is our Data App / Viz — and thanks to Streamlit, its pretty simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/0*xd0CNWfLajmsqTUI" /><figcaption>Getting there — most components are complete!</figcaption></figure><p>Let’s go back to GitHub and create a new file in our repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H8IwPyUigN7PzqUV" /><figcaption>I’m just going to create everyting in GitHub’s web interface for simplicity sake</figcaption></figure><p>We are going to use <a href="https://streamlit.io/">Streamlit</a> for our Data App. I’ve been a huge fan of Streamlit for awhile as it is a simple way to create functional Data Apps, just using Python. As I previously mentioned, I’m not a full stack engineer, so my front end coding skills are lacking. With Streamlit, all I have to worry about is Python.</p><p>We will build this out more, but let’s initially just import pandas and Streamlit and start writing a title and some content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zGRJ-f7qER3wKjSC" /><figcaption>Creating the first bits of our Data App</figcaption></figure><p>Commit that file and we are going to head to <a href="https://share.streamlit.io/">Streamlit Cloud</a> to get it up and running. If you haven’t already, create an account in Streamlit. They have a very generous free tier that we can use.</p><p>Click a New App from Existing Repo — if you haven’t yet, you’ll need to connect your GitHub account so that you can reference your newly created repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/0*NfqcNEf4rfjakcH-" /><figcaption>Creating your new app in Streamlit</figcaption></figure><p>Select your repository and select the Python that you just created for the Main file path. Click Deploy and wait for the magic to happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xj-QdZf2pn6uenyy" /><figcaption>Connecting your Streamlit Data App to your GitHub repository</figcaption></figure><p>Would you look at that — the Data App is up and running — now we just need to pull in our data and build some visualizations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*as6gY6-QQRuRlKIo" /><figcaption>Our first version of our Data App — more to come soon</figcaption></figure><p>Let’s go back to our app.py file and make some updates to pull in and visualize the data.</p><p>First, we are going to need to create a requirements.txt file in our repository so that we tell our data app to install Plotly Express.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lkc10jUw0OBthDXv" /><figcaption>We need to add a requirements.txt file so that we can use Plotly Express in our Data App</figcaption></figure><p>And in our app.py file, let’s add a few lines to read that csv file that your Data Bot will be updating and then a couple lines to build a line chart. Commit those updates and go back to your Data App to see your results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oGI7RD8vFVVoDD25" /><figcaption>With only 17 lines of code, you can create your Data App to read and view your data</figcaption></figure><p>As you can see — its not a great visualization….yet. The new Data Bot hasn’t collected enough data to see interesting data points over time. Also, we pulled in data for 645 Soccer teams, so the visualization is quite crowded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rQ47AWICVOBe62vO" /><figcaption>Our first result — not a great visualization yet, but it’ll get there</figcaption></figure><p>To fix the second issue, I’ll just quickly filter the dataframe so that we only have the top 25 teams, based on their average rating. It’s not the best solution, but will work for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H0OONJ7DIGEguynU" /><figcaption>Quick adjustment to filter our dataframe to the top 25 clubs</figcaption></figure><p>Ok — now it looks a bit easier to see the top 25 teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R14ePFmSKbuW8coB" /><figcaption>Starting to look a bit better — need to start collecting more data and probably enhance the visualizations a bit</figcaption></figure><p>But as more data flows in, the Data App will start to show interesting trends as team performance changes over time. Here is a <a href="https://share.streamlit.io/aaroncolesmith/538_viz/main/app.py">Data App that I created a while ago which has collected the FiveThirtyEight odds across multiple sports</a>, so you can see it creates quite a bit more interesting visual.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EDfwwMqOtDGywLc3" /><figcaption>Here is an example of one of my Data Apps that has been collecting data for ~5 months</figcaption></figure><p>Ok, so at this point, everything is good to go, your Data Bot should be automatically collecting data and your Data App should be visualizing the results. I’d love to see your results or if you have any questions, let me know.</p><p>Here are a couple helpful links for reference:</p><ul><li>Here is my Data Bot for this project: <a href="https://deepnote.com/project/Scraping-Global-Soccer-Rankings-deBxJDvUQMC9bz2-dnGDSA/%2Fnotebook.ipynb">https://deepnote.com/project/Scraping-Global-Soccer-Rankings-deBxJDvUQMC9bz2-dnGDSA/%2Fnotebook.ipynb</a></li><li>Here is the GitHub repository for my Data App: <a href="https://github.com/aaroncolesmith/club_soccer_rankings">https://github.com/aaroncolesmith/club_soccer_rankings</a></li><li>Here is the end result of my Data App: <a href="https://share.streamlit.io/aaroncolesmith/club_soccer_rankings/main/app.py">https://share.streamlit.io/aaroncolesmith/club_soccer_rankings/main/app.py</a></li><li>Here is my portfolio which also references a few other Data Apps / Projects I’ve worked on: <a href="https://aaroncolesmith.com/">https://aaroncolesmith.com</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3b302d9824c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clustering NBA Players Based on Statistics — an intro into Unsupervised Machine Learning]]></title>
            <link>https://medium.com/@aaroncolesmith/clustering-nba-players-based-on-statistics-an-intro-into-unsupervised-machine-learning-597ba8ea795a?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/597ba8ea795a</guid>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Thu, 28 May 2020 00:52:30 GMT</pubDate>
            <atom:updated>2020-05-28T00:52:30.886Z</atom:updated>
            <content:encoded><![CDATA[<h3>Clustering NBA Players Based on Statistics — an intro into Unsupervised Machine Learning</h3><p>What if I told you I could take about a million data points related to the past 70 years of NBA games and output clusters of players which would automagically tell you whether a player was a perennial superstar, or a towering big man, or a playmaking point guard?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*_sVx-bRXLD-2FwM3X-GadA.png" /><figcaption>The Superstar, the Playmaking Point Guard &amp; the towering Big Man</figcaption></figure><p>It is actually not as difficult as you may think. And helps us understand <a href="https://en.wikipedia.org/wiki/Unsupervised_learning">unsupervised machine learning (ML) algorithms</a>. If you don’t want to go through the entire article, <a href="https://bit.ly/nba-clusters">you can see the results here</a>, but I do implore you to read through.</p><p>At a high level, unsupervised ML algorithms take a large set of data and return identified patterns. Those patterns can then be used for other purposes, in our example, identifying what cluster a given player belongs to. Or perhaps, based on internet browsing data, what ads to surface.</p><p>Here is a brief glimpse of our data — specifically for one player — Michael Jordan. As you can see, there is one record for each season played and a number of statistics based on the season totals. Most of this data is being pulled from <a href="http://basketball-reference.com/">Basketball Reference</a>, some statistics I derived with some basic calculations from the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*xQNNYFQukvmhoh6FoBZGdw.gif" /></figure><p>Now the end goal is to create a visualization that encapsulates all of that data, so we are going to need to put that data through some algorithms to consolidate all of those data points.</p><p>At a high level, the data will need to undergo the following steps:</p><ol><li><strong>Scale the data so each attribute is of relative size</strong> — this means that leading the league in PPG with 30 will have a similar impact as leading the league in APG with 12.</li><li><strong>Summarize data attributes</strong> — the goal is to reduce the number of dimensions so that the dimensions can be used as inputs to a clustering algorithm, so there are statistics packages that can summarize the set of data to group similar attributes together.</li><li><strong>Cluster the results </strong>— the results of the previous two steps can be run through a clustering algorithm. A clustering algorithm will setup a number of clusters and group each data point based on distance to each cluster.</li></ol><p>The result can be combined with the original dataset at this point. Now that each record has a cluster and cluster coordinates, the results can be visualized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ScPmbTL9b49lDuij41xmsg.png" /></figure><p>So, as you can see from my results above, each data point was assigned to a cluster and based on the cluster values, you can plot the results on a scatter plot. Now to understand the data, you need to be able to explore the data and be able to hover over data points to see the results.</p><p>Its best to start looking at some of the outliers. In my scenario, I hypothesize that these are going to be the superstars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jXiBZZt-dp2gdVwPMKDMkg.png" /></figure><p>The bottom right data point is Russell Westbrook’s 2016–2017 season where he incredible averaged a triple-double. One would assume that the Big O, Oscar Robertson, would be right next to him, but unfortunately in 1962, not all statistics were being captured, so that data modifies the results of the algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6InHFdMznkkDO4TxunZEXQ.png" /></figure><p>So it appears that Cluster 2 is our superstars, along with Russell you’ll see players like Harden, MJ, Kobe, Wilt, Kareem, Hakeem &amp; Shaq. It’s also worth noting that big men tend to be towards the top right of the graph and guards are towards the bottom right. If we ran this with more clusters, I would hypothesize that the superstar cluster might separate into two clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wQM4q5rbBYHaBtAKZISw2A.gif" /></figure><p>By starting to explore the data, specifically the points that are furthest from the pack, you can start identifying clusters into different categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWrMXvYZ0e9fwFkcgZeQ7g.gif" /></figure><p>From this, you can start categorizing some other clusters:</p><p><strong>Cluster 0— Star Big Men — lots of Rebounds and Blocks</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*vuzc6FzKCJI6oZiJ.gif" /><figcaption>Mark Eaton — strong rep from Cluster 0</figcaption></figure><p><strong>Cluster 1— Role Player Guards — some Points, Assists and Steals</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*J29L-D4wdOpFP2UZ" /><figcaption>Derek Fisher — serviceable PG, and a perennial Cluster 1</figcaption></figure><p><strong>Cluster 2 — Superstars — highest level of Points, Rebounds, Assists, etc.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*Q1bOvv-7vrVISePz.gif" /><figcaption>Lots of options here, but Kareem and that Sky Hook graced the Superstar Cluster 2 in 17 total seasons</figcaption></figure><p><strong>Cluster 3 — Benchwarmers — not collecting many stats at all</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*dfCqtJskbPKS_MIq.gif" /><figcaption>Before coaching UConn, Kevin Ollie played 13 NBA seasons and never avg’d more than 8ppg</figcaption></figure><p><strong>Cluster 4 — Star Guards — lots of Assists, Points &amp; Steals</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*ZCGqS7cqhSizoEWs.gif" /><figcaption>John Stockton — the definition of assist leads Cluster 4</figcaption></figure><p><strong>Cluster 5 — Role Player Big Men — some Rebounds and Blocks</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/0*FF8T0eDolaO3Gl0d.gif" /><figcaption>Ryan Hollins — yea not much to say here</figcaption></figure><p><strong>Cluster 6 — Role Players — players getting a decent amount of Points, Rebounds, Assists</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/0*XtVaPnz7NesRk5a6.gif" /><figcaption>Getting checked by Giannis or living in a sea of mediocrity? Which is worse for Mike Dunleavy?</figcaption></figure><p>Now that the first results are in, you may be getting some ideas. What if we only used 2 clusters? What if we used 10? What if we only looked at the 90s?</p><p>So I put together a quick data web app using <a href="https://www.streamlit.io/">Streamlit</a> so that you can play around and test some different options: <a href="https://bit.ly/nba-clusters">https://bit.ly/nba-clusters</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6F59Z58BkyleBsmhuaRUfw.png" /></figure><p>I’ve also included two separate clusters based on player careers, so as opposed to looking at each season separately, looking at a player’s career. The first one looks at the entirety of a career, the second one is only looking at the stats per game. The latter is useful so that players that are still in the midst of their careers can show up alongside players that finished years ago.</p><p>Here are some interesting discoveries that I’ve noticed, feel free to share yours.</p><p><strong>Karl Malone and Kareem Abdul-Jabbar Put Out Some Major Stats Over Their Career</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OsLPoK09PhhWBuHLo3J2zw.gif" /><figcaption>Long careers of continued statistical performance</figcaption></figure><p><strong>Wilt Chamberlain was the Per Game King</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MN9__FBXI-sJiPPsd5nXIw.png" /><figcaption>Career average of 30+ PPG &amp; 22+RPG? Insane — and he didn’t even get the block stat, but I’m sure he swatted some shots in his day</figcaption></figure><p><strong>LeBron, MJ &amp; Larry?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8w6IYG1YPVWL55_Zd6TGA.gif" /><figcaption>Expecting Kobe? So was I, but it was Larry Bird clustered closely with MJ &amp; LeBron</figcaption></figure><p><strong>Steph Curry Stands Alone in Ushering a New Generation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_FidC6zT6q1sg0ZysXYVw.png" /><figcaption>Few players cluster closely with Steph as his onslaught of 3Ps has brought in a new generation of play</figcaption></figure><p><strong>Everything changed in 2016</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_7HUa8v2TqTSULBMCoHeg.png" /><figcaption>The bottom right was significantly less populated before Steph, Russ &amp; Harden started putting up numbers</figcaption></figure><p>Questions? Thoughts? Find anything cool? Let me know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=597ba8ea795a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Puzzle — Most Consecutive Seasons Increasing PPG]]></title>
            <link>https://medium.com/@aaroncolesmith/data-puzzle-most-consecutive-seasons-increasing-ppg-2f60824bf436?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f60824bf436</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[nba]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Tue, 03 Dec 2019 02:18:11 GMT</pubDate>
            <atom:updated>2019-12-03T02:18:11.116Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Puzzle — Most Consecutive Seasons Increasing PPG</h3><p>I enjoy having fun with data. Some people play Sudoku or solve crossword puzzles, but not me — I like to solve data puzzles.</p><p>Most data puzzles start with a hypothesis and a dataset and result with a conclusion to the hypothesis and some intelligence from the results. The “experiment” in the middle is the fun stuff — twisting around data to try to find answers.</p><p>Hopefully this will become a sort of series where I go through a “data puzzle” and if anyone has some ideas, please feel free to reach out to me.</p><p>This puzzle comes from <a href="https://twitter.com/BillSimmons">Bill Simmons</a> — Bill is a writer / podcaster / sports enthusiast who used to work at ESPN, but has recently started up <a href="https://www.theringer.com/">The Ringer</a> — a great website with a lot of accompanying audio / video content.</p><p>In a recent <a href="https://www.theringer.com/book-of-basketball">Book of Basketball 2.0 podcast</a>, Bill and his guest, <a href="https://twitter.com/ZachLowe_NBA">Zach Lowe</a>, were talking about the merits of James Harden, specifically looking at his historical significance and where he would rank in the top players of all time. While they produced many, interesting stats pertaining to Harden, there was one stat that they didn’t have a clear solution.</p><p>At around the 34 minute mark, just after ranking the top NBA beards of all time, Bill mentioned that if you flip one of Harden’s seasons, his scoring average increases for 10 straight seasons. This is a pretty crazy stat that shows that a player just keeps getting better and better each season.</p><p>Bill mentions that he doesn’t even know how to look up if that had ever happened before, so I started thinking through how I would find that answer. Which presents us with our first ever Data Puzzle:</p><h4>What player has had the most consecutive seasons increasing PPG each season?</h4><p>To start, I like to imagine what my data should look like. Both, imaging what the initial dataset would be and what the final dataset and visualization. I like to whiteboard, so here is the result (sorry for my handwriting).</p><p>The initial table would have the season, player, total points, total games and/or the PPG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkpLtfb7dSH2BesJb3AZAA.png" /></figure><p>Now after some data manipulation, I foresee this being the table that would be able to answer our question. In my best guess, we’d want to have an ID for each set of season(s) where the PPG increases each season. This would allow us to see the first season (min) and last season (max) and get the total number of seasons (count). We’d be able to aggregate some other data as well, but that’s all just cherries on top of the main goal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNFmPC4CHKrBDXSM7e8cKQ.png" /></figure><p>With this data, we’d be able to pull together a visualization like this, which shows PPG over time by season. And you could overlay the number of seasons to show each set of seasons where the PPG increases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHfE8Wh6QOdIV2HmjaVLgA.png" /></figure><p>And next, where should we get our data? This is often the hardest part solving a Data Puzzle.</p><p>I have a <a href="https://medium.com/@aaroncolesmith/scraping-data-from-bovada-96f2647fd152?source=friends_link&amp;sk=4e635c4d3607ec21ae6f31eb9de947a4">previous blog post talking about scraping data from web pages</a>, so I’m going to go with a similar approach here. <a href="https://www.basketball-reference.com/">Basketball Reference</a> is a great source of data, so I’m going to try to find what I’m looking for by pulling data from that website.</p><p><a href="https://www.basketball-reference.com/leagues/NBA_2018_totals.html">Here is an example of a page that has a table with the totals for the 2018 season</a> — as you can see, the URL has “2018” in it, so by replacing that value, we can iterate through a bunch of pages.</p><p>With just a bit of python code, we can iterate through pages from a start to an end and build a table that has multiple season totals for every player. That is a perfect starting point. (note: I’m not going to go line by line in this article, if anybody has any questions, feel free to reach out. I’ll also link this notebook if anyone is interested in playing around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAlJOtWUa-9LJeokmEMdYQ.png" /><figcaption>Scraping ~70 years of NBA data for further analysis</figcaption></figure><p>Now that we have our data, we have to do a few data manipulations so that the data grouped by player / year. In our initial dataset, players that were traded would have two records for that season. We don’t want that. We also need to add our PPG calculation.</p><p>After that, we need to create an “increase_index” column. This will be the column that iterates any time either (a) the previous record contains a different player or (b) the previous record contains a greater PPG. This will allow us to do another group by function to get our desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9qIJ73P2emCQmcRwFE0-xw.png" /><figcaption>Manipulating data</figcaption></figure><p>Let’s test that out by taking a look at James Harden and Kevin Durant to ensure that the increase_index changes if a season decreases in PPG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dbryjMe8PFnP6SIOtrYRqA.png" /></figure><p>Now we can do a groupby and sort the data to see which players have had the longest stretch of increasing their PPG each season….drumroll please.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6KN9ZW--TlwBq2_kFzkKYg.png" /></figure><p>If you said Derek Harper, J.J. Redick &amp; DeAndre Jordan, you win!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iLMMu1lhtum_IIotCFzW6Q.png" /><figcaption>Each player increased their PPG for 8 straight seasons</figcaption></figure><p>We can visualize each of these player’s PPG by season to validate everything worked correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR89ta458qNDWLU3YIfoJA.png" /><figcaption>Derek Harper’s PPG by season</figcaption></figure><p>J.J. was so close to getting 9 seasons, missing out by .025 PPG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4gQfmEmOl9QT410b2e7gA.png" /></figure><p>And somehow DeAndre Jordan out-did him by missing out by .024 PPG. Insane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dh3lpIzqEmxFc2she7-dvA.png" /></figure><p>All of these streaks have come to an end. What about most active? Who has a chance to get to 9 seasons increasing PPG each season? We can create a new dataframe and filter it to find that out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vuIoD0rljEmiXdYshLHgKw.png" /></figure><p>Well, well, well. There is Mr. Harden. He’s been steadily increasing his totals his entire career. And while not hitting 9 seasons increasing each time, he is currently on 6 seasons. He’ll have to put up some historic numbers to increase from 36.13 PPG. As I’m writing this (early December ’19) he’s actually at 38.9 PPG, so who knows? Visualizing James Harden’s PPG each season is incredible…barely missing out on 2014, he could have increased each season which would currently put him at 10 seasons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5WGG_7YOyIH7URvL90qhvw.png" /></figure><p>And just below him is his MVP rival, Giannis Antetokounmpo. Giannis has also had a meteoric rise, increasing his PPG in each of his first 6 seasons. He also is currently on pace to hit his seventh season.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2SfTBgmZa8qQGCbAF4xlA.png" /></figure><p>Ok. I am going to break for now, there are tons of other avenues I could take this analysis — consecutive seasons increasing RPG, APG, 3PA, etc. — but I’ll leave that for another day.</p><p>If you have any questions or have a puzzle you’d like me to take a look at, feel free to leave a comment or reach out.</p><p>If you want to see the notebook I created for this, check it out here: <a href="https://nbviewer.jupyter.org/github/aaroncolesmith/data-puzzles/blob/master/Consecutive%20NBA%20Seasons%20Increasing%20PPG.ipynb">NBViewer</a> or <a href="https://github.com/aaroncolesmith/data-puzzles/blob/master/Consecutive%20NBA%20Seasons%20Increasing%20PPG.ipynb">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f60824bf436" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing Scraped Bovada Data]]></title>
            <link>https://medium.com/@aaroncolesmith/visualizing-scraped-bovada-data-8cb370e4c821?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cb370e4c821</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Tue, 17 Sep 2019 17:22:50 GMT</pubDate>
            <atom:updated>2019-09-17T17:22:50.114Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@acs2210/scraping-data-from-bovada-96f2647fd152">In part 1</a>, I showed how you can use Jupyter and some handy packages to scrape data from Bovada to start collecting data on Bovada bets that are interesting to you. The insights start to appear as you start collecting data over time. That first example just pulled the data, now we are going to start having fun with it.</p><p>Hopefully, at this point, you have been collecting data on a routinely basis. If not, no big deal, but you should start collecting data files so that you can see some visualizations of how they trend over time. I’ve been tracking the odds to win the world series 66 times over the past 5–6 months.</p><p>There are many visualization packages you can import into Jupyter to start visualizing data. <a href="https://matplotlib.org/">Matplotlib</a> is normally the default most people turn to, for this example, I’m going to take it a step further using <a href="https://plot.ly/">Plotly</a>.</p><p>Previously, our Import Packages cell imported Plotly, but I’m going to re-import it in a different way because I’ve been getting some errors with the previous import. So you’ll just need two lines to import Plotly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cdab52628b7f1355da79864a44fa7f1/href">https://medium.com/media/8cdab52628b7f1355da79864a44fa7f1/href</a></iframe><p>Next, we are going to <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.unstack.html">groupby and unstack</a> and create a new dataframe specifically used for visualizations. Your resulting dataframe should look something like this where the index is now all the dates that collected data and the fields are all of the possible outcomes of the bet…for our example, they’d be MLB teams that could win the World Series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NSzPdMS1xs0MPmnCCJlt5g.png" /><figcaption>Unstacked dataframe for Plotly</figcaption></figure><p>Now let’s build a visualization in Plotly.</p><p>We are going to need to tell Plotly which fields will be our X values (our dates, or g.index) and which fields will be our Y values (all of our columns, representing each betting outcome).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17b31b6af9561795d5f5f9bb8eb52197/href">https://medium.com/media/17b31b6af9561795d5f5f9bb8eb52197/href</a></iframe><p>Now with just those two lines of code, you get a very nice visualization with some built in functionality to hover over data to view it and be able to remove fields and have the graph update live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwOeJhc2UrmrS6Zp2S74sg.gif" /><figcaption>MLB odds to win World Series over time</figcaption></figure><p>What you can understand from looking at the visualization of the MLB odds to win the World Series over time, as time goes, the odds increase as teams continue to lose and get further and further away from being able to win the World Series. We can also filter the dataframe so that we only see the favorites and filter out some of the noise seen above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfKgzxmYJfgia85KqgHa8Q.gif" /><figcaption>Filtered view to only show the favorites</figcaption></figure><p>Pretty cool, huh? Feel free to take a look at the full notebook that has both part 1 to scrape and store the data and part 2 to visualize the data here: <a href="https://github.com/acs2210/bovada/blob/master/BovadaBookVisualized.ipynb">Bovada Book Visualized</a>.</p><p>Now you can see start seeing how real world events have affected the betting odds over time.</p><p>Here are some cool bets that I’ve tracked in the past:</p><h3>The Winner of Game of Thrones:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tGXpuMJ-nlj1zVfSUZxug.png" /><figcaption>Winner of Game of Thrones odds</figcaption></figure><p>It is interesting how pre-season, Bran Stark was the favorite, but during the season Jon Snow caught up with him. Only to be undone once Jon killed his Aunt / Lover (spoiler alert).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*NSlkiFWdEluE4SD7jBU20Q.gif" /><figcaption>Jon Snow is still my king</figcaption></figure><h3>Odds to Win 2020 Election:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*11H4eVQf7GUtHoSAVDY96g.png" /><figcaption>Odds to win 2020 election</figcaption></figure><p>The incumbent has been the betting favorite the entire way, but it is interesting to see how the democratic candidates shifting based on performances during debates.</p><h3>Best Picture for Films in 2018:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1rtSZgDbXVtIYtbRIUcZLA.png" /><figcaption>Odds to win the Oscar for the Best Picture</figcaption></figure><p>It is worth noting that while Roma is the favorite the entire time, Green Book was the eventual winner. Close to the event, the odds for those two films started closing in on each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*Lv4i9VVbfwm-xs9woaISzg.gif" /><figcaption>How you like them apples</figcaption></figure><p>So, go forth, collect data, visualize it….if you feel the need, place some bets based on the data. Feel free to report back, I’d love to hear some thoughts or examples that you’ve created. If you have any questions, let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cb370e4c821" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scraping Data From Bovada]]></title>
            <link>https://medium.com/@aaroncolesmith/scraping-data-from-bovada-96f2647fd152?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/96f2647fd152</guid>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-analytics]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Fri, 09 Aug 2019 16:52:23 GMT</pubDate>
            <atom:updated>2019-08-09T16:52:23.008Z</atom:updated>
            <content:encoded><![CDATA[<p>I have previously mentioned that <a href="https://medium.com/@acs2210/where-to-start-d2704fa5d529">I’m a Product Manager with a data curiosity</a>, so here is my first post about some of the data that I play around with. If you are looking for my <a href="https://medium.com/@acs2210/product-managers-build-problems-not-solutions-c528cc16f50a">first Product-related post, you can check it out here</a>.</p><p>While I wouldn’t call myself a gambler, I do like to use <a href="https://www.bovada.lv/">Bovada</a> as a data source to see how some trends over time for some competitions. I have tracked the NBA, NCAA, Presidential Election, Oscars and even the Game of Thrones’ winner. This just goes back to my data curiosity, it is interesting to see data change over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*eVBx_WBljFes9GcS.gif" /></figure><p>So, how do I do it? Well, I am an avid user of <a href="https://jupyter.org/">Jupyter</a> which is a notebook interface that allows you to take advantage of a number of different programming languages…I use it mostly for Python.</p><p>While Python is great for data analysis, Jupyter also allows for other libraries to enable other functions as well. In this article, I use <a href="https://www.seleniumhq.org/">Selenium</a> to scrape Bovada to build a dataset that can be used for data analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9T_Ky8lvzutWPs4YeCZ09Q.png" /><figcaption>We’ll be scraping from the web to a Jupyter notebook</figcaption></figure><p>I’ll provide a link to the full solution at the end, but I want to go cell by cell so that you understand what we’re doing.</p><p>First, import some packages to help us accomplish our goal. You’ll see we are importing Selenium, Datetime, CSV, Numpy and Pandas. Those all will help us read or grab data to build our dataset.</p><p>I also import <a href="https://plot.ly/">Plotly</a> as a data visualization tool that I’ll cover in another article…data is only effective if you can use it to tell a story, which is where the visualization comes in.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddfc233ff5babe105a6a8ec2827b9dd0/href">https://medium.com/media/ddfc233ff5babe105a6a8ec2827b9dd0/href</a></iframe><p>Ok, after everything is imported, we will setup a couple of functions. The first ones are pretty simple and will be used for data analysis in a future post.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1056471bac7107cdabaf3ff54b7b972a/href">https://medium.com/media/1056471bac7107cdabaf3ff54b7b972a/href</a></iframe><p>The next function is where all the scraping comes in. I tried to comment areas so that you can follow along, but I’ll give a high level overview here as well. It is long, but not that complicated.</p><p>We build this function to pass in two values: the Bovada url to scrape and a filename to read in historical data and save the data off.</p><p>First we initiate Selenium, you’ll need to download a <a href="https://chromedriver.chromium.org/">ChromeDriver</a> and point this code to your local ChromeDriver. The end of that first section will launch Selenium to the url that you passed in.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a698af22a45e454100bd209081baefc5/href">https://medium.com/media/a698af22a45e454100bd209081baefc5/href</a></iframe><p>Next we scrape values from the website based on their element name, as defined by Bovada’s web developers. You can use Chrome’s dev tools to find the elements or use other Selenium functions to scrape the data you are looking for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VXdHgWNGRNwRbOoeD3CDOA.png" /><figcaption>You can use a variety of web elements…for this example, I used class_name</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd58655d2b31deecc44d263d6fb6b605/href">https://medium.com/media/dd58655d2b31deecc44d263d6fb6b605/href</a></iframe><p>Our next part is to check if we have an input file. Since each run is a point in time, I create a history file that we add on to so that we have a historical view of this data over time. If there is no input file, we’ll continue on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92c44d0f8921924c166f44454eb89998/href">https://medium.com/media/92c44d0f8921924c166f44454eb89998/href</a></iframe><p>Next, we initiate three list objects for the three pieces of data that we care about: the title of the bet (i.e. World Series 2019), the outcome (i.e. Houston Astros) and the bet price (i.e. +225). We are going to loop through the Selenium objects we previously loaded to append each value in that list to the list object. The title doesn’t require to loop through since it’ll be the same for each.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e40268aba7b5a30fb0da239e80aaa3a6/href">https://medium.com/media/e40268aba7b5a30fb0da239e80aaa3a6/href</a></iframe><p>Our final section will be to take that data from the list objects and put it in a Pandas dataframe. We will add the timestamp so that we can look at the data over time and we will append it to our input dataframe, if it exists. Finally, we’ll write a file so that we have our historical data stored locally, close the browser, and return the dataframe for further data analysis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5891e36d0591b361f3f3ab90fefbffb/href">https://medium.com/media/c5891e36d0591b361f3f3ab90fefbffb/href</a></iframe><p>When all that is created as a function, all that is left is to set a <a href="https://www.bovada.lv/sports/baseball/mlb/2019-world-series-odds-to-win-201910240000">url</a> and a filename and run the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jY6-rKOeejgYAOYvTpCk-Q.png" /><figcaption>Current odds in Bovada — Go Reds…maybe next year</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6fZj0470CiAnjZii-dtfg.png" /><figcaption>Current odds scraped into my pandas dataframe</figcaption></figure><p><a href="https://github.com/acs2210/bovada/blob/master/BovadaBook.ipynb">Now you have your completed notebook.</a></p><p>As you run this overtime, you’ll start to collect a dataset overtime which you can use for data analysis and visualization. I’ll talk about that in my next data related post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96f2647fd152" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Product Managers Build Problems, Not Solutions]]></title>
            <link>https://medium.com/@aaroncolesmith/product-managers-build-problems-not-solutions-c528cc16f50a?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c528cc16f50a</guid>
            <category><![CDATA[prioritization]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[product]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Thu, 08 Aug 2019 11:36:05 GMT</pubDate>
            <atom:updated>2019-08-08T11:51:23.675Z</atom:updated>
            <content:encoded><![CDATA[<p>A number of these blog posts that I am writing are going to be referencing an article or a piece of an article that I recently read. This may benefit you, it may not, but my intention is to build a library of principles which I follow to be the best Product Manager I can be.</p><p>I recently read <a href="https://www.pendo.io/pendo-blog/what-your-product-teams-want-to-know-and-how-you-can-tell-them/">What Your Product Teams Want to Know (and How You Can Tell Them)</a> on the Pendo blog and a portion of the article related to a principle that I wanted to call out: Product Managers need to focus more on the problem and understanding the problem behind a feature request.</p><p>While this article was more targeted towards folks working with Product Managers (i.e. stakeholders), it does well to articulate a point that I think is one of the main responsibilities of Product Managers — synthesizing and analyzing a variety of feature requests in many different forms to build a prioritized list of problems to solve with their team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KURZ0mZQ_hD_QKzkKLYDaw.png" /><figcaption>Sorry for the crudeness off this drawing — I’m not an artist</figcaption></figure><p>Without a Product Manager, requests come in, engineers fix the request and the end product is not always a valuable solution. I am reminded of the classic <a href="https://en.wikipedia.org/wiki/Tree_swing_cartoon">tree swing metaphor</a> showing the many ways a product or feature can be created incorrectly due to this breakdown in communication and process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8aifKYfbk7EXfB5KEKgq1g.jpeg" /></figure><p>TLDR — One of the main responsibilities of a Product Manager is to understand the problems behind all the requests they receive so that they can prioritize the problems and work with engineering to find a solution.</p><p>Questions? Feedback? Let me know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c528cc16f50a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where to start…]]></title>
            <link>https://medium.com/@aaroncolesmith/where-to-start-d2704fa5d529?source=rss-faeed41249e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2704fa5d529</guid>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Aaron Smith]]></dc:creator>
            <pubDate>Tue, 06 Aug 2019 23:34:49 GMT</pubDate>
            <atom:updated>2019-08-06T23:37:10.291Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, my name is <a href="https://www.linkedin.com/in/aaroncolesmith/">Aaron Smith</a>. I am currently a Product Manager at <a href="https://oliveai.com/">Olive</a> where we are building the digital workforce to cut a trillion dollars out of healthcare spending.</p><p>I wanted to start writing, so here is my first attempt. My main goals are to:</p><ol><li>Centralize a lot of good things that I’m passionate about, specifically around Product and Data</li><li>Talk about some of the work that I’ve done in the past</li><li>Interact with some like minded folks</li></ol><p>I’m going to keep it pretty casual and try to get a wide range of thoughts and hopefully keep a pretty good cadence of content.</p><p>Welp, this all I got for the intro, I’m looking forward to building some actual content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*4aPGs7Aj3KTIsD7NKrAf6A.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2704fa5d529" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>