<?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 Jason Schvach on Medium]]></title>
        <description><![CDATA[Stories by Jason Schvach on Medium]]></description>
        <link>https://medium.com/@jasonschvach?source=rss-7d17aa6affc0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bKfU7h_4ZY4ZLkWj.</url>
            <title>Stories by Jason Schvach on Medium</title>
            <link>https://medium.com/@jasonschvach?source=rss-7d17aa6affc0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 14:13:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jasonschvach/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[Stop Using BeautifulSoup to Parse HTML Table Tags: Discover the Power of Pandas]]></title>
            <link>https://medium.com/@jasonschvach/stop-using-beautifulsoup-to-parse-html-table-tags-discover-the-power-of-pandas-381bb8878695?source=rss-7d17aa6affc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/381bb8878695</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[beautifulsoup]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Jason Schvach]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 14:27:25 GMT</pubDate>
            <atom:updated>2023-04-11T06:47:23.631Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRPKNu5a7_j8O-_PEWXpxA.png" /></figure><p>BeautifulSoup has long been the go-to library for web scraping and parsing HTML in Python. In fact, I love it and use it 90% of the time for my data pulling from HTML.</p><p>However, when it comes to parsing HTML tables, I have come across far too many articles on Medium that demonstrate using BeautifulSoup instead of more efficient and easier alternatives. While working with tables can be a great way to learn BeautifulSoup due to their rigid structure, it’s not the most efficient or easiest method for handling &lt;table&gt; tags. Enter Pandas — a versatile library that not only simplifies data manipulation but also provides a powerful alternative to BeautifulSoup for parsing HTML tables.</p><p>In fact, Pandas uses BeautifulSoup under the hood for its HTML parsing capabilities. It’s worth noting that majority of the time when parsing table tags, you are going to put the data into a table or dataframe with Pandas anyway. Additionally, if you are looking to convert the data into other structures such as JSON, Pandas can do that as one-liners too. Let’s dive into a comparison of these two approaches, showcasing why you should consider making the switch from straight up BeautifulSoup to Pandas for parsing HTML tables.</p><p>Example with BeautifulSoup: First, let’s take a look at how to extract data from an HTML table using BeautifulSoup. For this example, we will use a simple HTML page containing a &lt;table&gt; tag:</p><h4><strong>BeautifulSoup</strong></h4><pre>import requests<br>from bs4 import BeautifulSoup<br>import pandas as pd<br><br>url = &#39;https://www.basketball-reference.com/leagues/NBA_2023.html&#39;<br>response = requests.get(url)<br>soup = BeautifulSoup(response.text, &#39;html.parser&#39;)<br><br>table = soup.find(&#39;table&#39;, {&#39;id&#39;:&#39;per_game-team&#39;})<br><br>header = [th.text.strip() for th in table.find(&#39;thead&#39;).find_all(&#39;th&#39;)]<br>data = []<br><br>for row in table.find_all(&#39;tr&#39;):<br>    rowData = [td.text.strip() for td in row.find_all([&#39;th&#39;,&#39;td&#39;])]<br>    if len(rowData) == len(header):<br>        data.append(rowData)<br><br>df = pd.DataFrame(data, columns=header)</pre><p>The same results can be accomplished much easier with simply:</p><p><strong>Pandas</strong></p><pre>import pandas as pd<br><br>url = &#39;https://www.basketball-reference.com/leagues/NBA_2023.html&#39;<br>df = pd.read_html(url, attrs={&#39;id&#39;:&#39;per_game-team&#39;})[0]</pre><p>To extract the href attribute from the &lt;a&gt; tags within the table, you can modify the code as follows:</p><p><strong>BeautifulSoup</strong></p><pre>import requests<br>from bs4 import BeautifulSoup<br>import pandas as pd<br><br>url = &#39;https://www.basketball-reference.com/leagues/NBA_2023.html&#39;<br>response = requests.get(url)<br>soup = BeautifulSoup(response.text, &#39;html.parser&#39;)<br><br>table = soup.find(&#39;table&#39;, {&#39;id&#39;: &#39;per_game-team&#39;})<br><br>header = [th.text.strip() for th in table.find(&#39;thead&#39;).find_all(&#39;th&#39;)]<br>header.insert(2, &#39;href&#39;)<br>data = []<br><br>for row in table.find_all(&#39;tr&#39;):<br>    rowData = []<br>    for cell in row.find_all([&#39;th&#39;, &#39;td&#39;]):<br>        # Check if the cell has an &lt;a&gt; tag<br>        link = cell.find(&#39;a&#39;)<br>        if link:<br>            href = link[&#39;href&#39;]<br>            rowData.extend((cell.text.strip(), href))<br>        else:<br>            rowData.append(cell.text.strip())<br><br>    if len(rowData) == len(header):<br>        data.append(rowData)<br><br>df = pd.DataFrame(data, columns=header)</pre><p>Furthermore, with Pandas version ≥ <em>1.5.0, </em>you can utilize the extract_links:</p><p><strong>Pandas</strong></p><pre>import pandas as pd<br><br>url = &#39;https://www.basketball-reference.com/leagues/NBA_2023.html&#39;<br>df = pd.read_html(url, attrs={&#39;id&#39;:&#39;per_game-team&#39;})[0]<br>df_links = pd.read_html(url, attrs={&#39;id&#39;:&#39;per_game-team&#39;}, extract_links=&#39;body&#39;)[0]<br><br>df_links[&#39;href&#39;] = df_links[&#39;Team&#39;].str[1]<br>df = pd.merge(df, df_links[&#39;href&#39;], how=&#39;left&#39;, left_index=True, right_index=True)</pre><p>Both methods yield the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8h8aLUS5DfJPNVSjsz_UA.png" /></figure><p><strong>Conclusion</strong></p><p>While BeautifulSoup is an amazing library for web scraping and parsing HTML in general, when it comes to parsing HTML tables, Pandas offers a more efficient and streamlined approach. With Pandas, you can quickly convert the parsed data into tables, dataframes, or even other formats like JSON. By leveraging the power of Pandas, you can save time, simplify your code, and focus on more important aspects of your data analysis and machine learning projects.</p><p>Thank you for reading this article, and I hope you’ll consider making the switch from BeautifulSoup to Pandas for parsing HTML tables in your future projects.</p><p>If you have any questions or need help with your web scraping projects, don’t hesitate to reach out. I’d be more than happy to assist and share my expertise.</p><p>Additionally, if you’re interested in discussing sports data or the application of machine learning to sports analytics, I’d love to chat and exchange ideas. Together, we can learn, grow, and create better solutions for data-driven decision-making in sports and beyond.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=381bb8878695" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Illusion of Luck: How Perception Shapes Our Experiences]]></title>
            <link>https://medium.com/@jasonschvach/the-illusion-of-luck-how-perception-shapes-our-experiences-865a690057f?source=rss-7d17aa6affc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/865a690057f</guid>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[luck]]></category>
            <category><![CDATA[perception]]></category>
            <dc:creator><![CDATA[Jason Schvach]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 08:42:17 GMT</pubDate>
            <atom:updated>2023-04-11T06:50:04.635Z</atom:updated>
            <content:encoded><![CDATA[<p>We’ve all experienced times when everything seems to go wrong. It feels like nothing can go right, and we wonder why negative events keep happening to us. Conversely, we sometimes run into a string of good fortune, where everything goes according to plan. Are these instances simply a matter of luck, or is there more to it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*Gq-nSGGmn-tLESnV685Ifg.png" /><figcaption>Sometimes, it feels like even our clothes aren’t right.</figcaption></figure><p>And just like that, our luck can change…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*UzxCnXapVUo5vtTr_CMswQ.gif" /><figcaption>Sometimes, we experience lucky coincidences, such as wearing the right clothes for unexpected circumstances.</figcaption></figure><p>Sometimes, we run into a string of good luck and iregardless of effort we get a positive outcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RjHmx0esI2GBXoo05Z2_WQ.png" /><figcaption>Perhaps we create our own luck.</figcaption></figure><p>In reality, these experiences may not be as extraordinary as they seem. Rather, they are our observations of rare events occurring based on our perception and how the events relate to one another.</p><p>I came across this book by David Hand called <em>The Improbability Principle.</em> In his book, Hand explores how the rare events we sometimes associate with good or bad luck are actually a result of our perception of these occurrences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*F_fdTa-iAn0mVYouqhX_Vg.jpeg" /></figure><p>Hand outlines five “laws” that help to explain how these seemingly improbable events are not as unusual as they might appear:</p><p>The 5 ‘Laws’ are briefly described as:</p><ol><li>the law of inevitability — Something will happen…(obviously!)</li><li>the law of truly large numbers — given enough opportunities, the probabilities of even very unlikely events can mount up to be almost certain</li><li>the law of selection — You can make things as likely as you want if you choose after the event. Like “connecting” the dots AFTER the event occurred…regardless if they actually are related.</li><li>the law of the probability lever — Slight changes can make highly improbable events almost certain. For example: Your co-worker who you JUST met at the college campus bookstore happens to be in 2 of the exact same classes that you’re enrolled in!! Out of 30,000 possible students and 100s of different courses to enroll in…what a coincidence!! Crazy? Not so much… it also just so happens you and him/her a) go to the same school, b) are entering in the the same academic school year c) pursuing the same/similar degrees, d) need the same credits/courses, etc, etc, etc. So is it really that <em>crazy</em> you’d be in the same classes?</li><li>the law of near enough — you consider similar events as identical. If you relax your conditions enough, you can make probabilities as high as you like.</li></ol><p>The fifth law is particularly intriguing, as it highlights how our perception of coincidences is entirely within our control. Hand shares an example from his own life, when he bumped into his brother in Paris. While the encounter was surprising, he would have been equally surprised to meet other family members, friends, or coworkers during his trip. Moreover, learning about their overlapping travel plans after the fact, or discovering they had been in France or even Europe, and not necessarily in Paris at the same time, would have also been astonishing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Y_3pphxawidCnWeXEGHJjQ.png" /><figcaption>I saw Batman today! Well, really, I saw a man and his cat.</figcaption></figure><p>Another aspect to consider is the idea of relativity. Rare positive or negative events happen to us all the time, but we tend not to notice them when they occur within time frames that are fairly equal in length. This is because there’s no disruption in what we have been accustomed to observing in our daily lives — it feels like “business as usual.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IX2imcyRj62bduuZ5Lt1sw.gif" /><figcaption><em>Like deja vu, the clumping of rare events are just a glitch in the matrix</em></figcaption></figure><p>However, rare events do not occur at pre-determined intervals. Sometimes, two events happen closer together, creating a sense of good fortune or misfortune. When this happens, our awareness of these “rare” events is heightened, leading us to question our perceived luck.</p><p>Let’s look at visual representation of a time frame of three ‘rare’ events occurring within a time frame. These events can be:</p><p>positive — i.e. a promotion at work, a new baby in the family, a relative/friend getting engaged, your favorite sports team winning a championship, you bump into an ex-boyfriend/girlfriend, etc</p><p>negative — i.e. going through a divorce, family member passes away, laid off from work, car accident, you bump into an ex-boyfriend/girlfriend (notice bumping into an ex can be positive or negative depending on the circumstances), etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*azwaaKvuE9PrpuSzhcWizw.jpeg" /></figure><p>Should these events happen to fall within relatively equal distance/time from each other as in Scenario A, they go unnoticed. At the very least, maybe you do make a note of the rare occurrences, but soon it is forgotten and most likely, these events are happening all the time, you just haven’t made note of it.</p><p>But events don’t just occur pre-planned in equal increments. One of those events will happen closer to the other event as seen in Scenario B and/or Scenario C. This leaves a big gap between 2 events, while clumping the other 2 events close together. Thus, creating that artificial belief of “Wow! I can’t believe these things are happening! I just have good fortune / I just can’t catch a break!”</p><h3><strong>Conclusion</strong></h3><p>Luck may be more a matter of perception than anything else. By understanding the principles behind seemingly improbable events, we can better appreciate the role that perception plays in shaping our experiences. Ultimately, it may be that we create our own luck, simply by adjusting our perspective on the events that unfold around us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=865a690057f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>