<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Patman17</title>
    <description>The latest articles on Forem by Patman17 (@patman17).</description>
    <link>https://forem.com/patman17</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F223995%2Fdc5d831f-366d-4f2a-b0a8-218eebab6ffc.png</url>
      <title>Forem: Patman17</title>
      <link>https://forem.com/patman17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/patman17"/>
    <language>en</language>
    <item>
      <title>Beginner Guide to Optimizing Pandas Calculations</title>
      <dc:creator>Patman17</dc:creator>
      <pubDate>Mon, 04 Nov 2019 03:04:00 +0000</pubDate>
      <link>https://forem.com/patman17/beginner-guide-to-optimizing-pandas-calculations-229h</link>
      <guid>https://forem.com/patman17/beginner-guide-to-optimizing-pandas-calculations-229h</guid>
      <description>&lt;p&gt;Recently, I started to compete on some competitions on Kaggle and there was one competition that had certain time restrictions that made me look into optimizing my Pandas calculations.&lt;/p&gt;

&lt;p&gt;Being a first year student in data science and coding in python, I had limited experience with Pandas and its inner workings. However, one thing I noticed first hand was how slow it ran when utilizing any some of "for loo". This was detrimental as I was only used to old C++ type coding that utilize "for loops" pretty frequently. Thus, I started to look at different ways to implement calculations on Pandas data frames.&lt;/p&gt;

&lt;p&gt;In this post, I will highlight all the various ways to do calculations on Pandas data frames and my picks for optimizing calculations. I will be utilizing a dataset called df_train that has 509762 rows to stimulate the calculations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1: "for loop" over every element of a Pandas series.
&lt;/h2&gt;

&lt;p&gt;This is the most worst way to do any calculations but it can conceptually be the easiest way to implement a solution. I suggest you avoid this method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;%%&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="n"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Dir'&lt;/span&gt;&lt;span class="p"&gt;])):&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'S'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Dir'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;180.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'dx'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;CPU times: user 10.5 s, sys: 91.2 ms, total: 10.6 s&lt;br&gt;
Wall time: 10.8 s&lt;/p&gt;
&lt;h2&gt;
  
  
  Method 2: Use "iterrow" for row operations.
&lt;/h2&gt;

&lt;p&gt;If you want to iterate over each row of a dataframe this would be the method as it was built to be more compatible with Pandas. Again I would avoid using this method as I actually got slower computation time. (5x slower)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;%%&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="n"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iterrows&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;   
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'S'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Dir'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;180.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'dx'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;CPU times: user 49.3 s, sys: 1.22 s, total: 50.6 s&lt;br&gt;
Wall time: 51.9 s&lt;/p&gt;
&lt;h2&gt;
  
  
  Method 3: Use apply function.
&lt;/h2&gt;

&lt;p&gt;This method would be my first prefer method as it is conceptually easy and require least amount of code but again the downside is that you have no utilizing vectorization of the numpy array. It is still iterating over each row but does so with a number of internal optimizations, such as using iterators in Cython. For my example, however it was slightly slower than the original method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;%%&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'dx'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;180.0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;CPU times: user 14.2 s, sys: 455 ms, total: 14.7 s&lt;br&gt;
Wall time: 15 s&lt;/p&gt;
&lt;h2&gt;
  
  
  Method 4: Vectorization over Pandas Series
&lt;/h2&gt;

&lt;p&gt;Vectorization mean making the calculation of over the whole numpy array aka do the whole column calculation all at once. This utilize the whole benefit of the numpy library and this method is what we want to strive for.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;%%&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'dx'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;180.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;CPU times: user 13.7 ms, sys: 3.66 ms, total: 17.4 ms&lt;br&gt;
Wall time: 16.3 ms&lt;/p&gt;

&lt;p&gt;As we can see the code is much simpler and it is 100x faster than row iterative methods.&lt;/p&gt;
&lt;h2&gt;
  
  
  Method 5: Vectorization over Numpy array
&lt;/h2&gt;

&lt;p&gt;The final improvement we can do is convert the Pandas dataframe to an actual array before we do the calculation. It will give a slight boost in calculation speed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;%%&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'dx'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;df_train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;180.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;CPU times: user 7.87 ms, sys: 3.03 ms, total: 10.9 ms&lt;br&gt;
Wall time: 12.1 ms&lt;/p&gt;

&lt;p&gt;Again this method is not necessary but there is a good speed boost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We want to avoid any row iterative method to perform calculations on Pandas dataframe. However, for certain transformations like string manipulations I found that .apply would be my go to as it is simple and gets the job done. &lt;/p&gt;

&lt;p&gt;But if we are utilizing all numpy based operators we need to try Method 4 or 5 as we are truly utilizing the power of the numpy based dataframe. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Intro to Web Scraping a Table</title>
      <dc:creator>Patman17</dc:creator>
      <pubDate>Fri, 27 Sep 2019 19:06:19 +0000</pubDate>
      <link>https://forem.com/patman17/intro-to-web-scraping-a-table-441b</link>
      <guid>https://forem.com/patman17/intro-to-web-scraping-a-table-441b</guid>
      <description>&lt;h2&gt;
  
  
  Intro to Web Scraping a Table
&lt;/h2&gt;

&lt;p&gt;What is web scraping? From my limited knowledge web scraping is getting info off a webpage by utilizing the underlining HTML code that contains this vital information. &lt;/p&gt;

&lt;p&gt;Today, I am going to walk through the general process to web scrape a table off the internet. In the process, I hope to answer a random question: Does cold weather affect quarterback play?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/x3C3ifJk4otwc/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/x3C3ifJk4otwc/giphy.gif" alt="hi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;responses&lt;/strong&gt; (HTTP library)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BeautifulSoup4&lt;/strong&gt; (Parser library)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pandas&lt;/strong&gt; (data manipulation library)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://realpython.com/python-web-scraping-practical-introduction/#setting-up-your-python-web-scraper"&gt;Use this link for more setup details&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of Web Scraping
&lt;/h2&gt;

&lt;p&gt;1) Get the response&lt;br&gt;
2) Find the object&lt;br&gt;
3) Parse and store the object&lt;br&gt;
4) Finalize the data &lt;/p&gt;
&lt;h2&gt;
  
  
  1) Get the response.
&lt;/h2&gt;

&lt;p&gt;This is the easy part. You use 'responses' to get the response from the URL and then you turn the response into a soupy 'soup' with BS4 that it then can navigate and parse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'http://www.espn.com/nfl/qbr/_/type/player-week/week/3'&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#getting url response
&lt;/span&gt;&lt;span class="n"&gt;nfl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;soup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'html.parser'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#turning the response into soup
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  2) Find the object (the hard part)
&lt;/h2&gt;

&lt;p&gt;For beginners this is the hard part because HTML is a little daunting to decipher at the beginning but there is some underlying principles to help. &lt;/p&gt;

&lt;p&gt;With BS4, you can navigate the HTML soup in two ways. &lt;/p&gt;

&lt;p&gt;1) Parent, Child, Sibling Hierarchy&lt;br&gt;
HTML is structured with higher level 'Parent' tags (classifiers) with 'Child' tags that it encompasses. BS4 has method to manually move line by line through the HTML if you need to fine tune where you are at. &lt;/p&gt;

&lt;p&gt;2) .find( ) and .find_all( )&lt;/p&gt;

&lt;p&gt;This is the easier method. You can tell BS4 to find the specific type of tag and what 'name' tag you are looking for. &lt;/p&gt;

&lt;p&gt;How do you know what name you want? Easy, just navigate the webpage and right click the object/table you want to parse and 'inspect' it. This should open up a window that will direct you to the corresponding HTML code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Pr7j69y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jksyr4wdslixf62x6ujr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Pr7j69y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jksyr4wdslixf62x6ujr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Even easier in HTML are tables because they are structured fairly similar for most webpages. &lt;/p&gt;

&lt;p&gt;1) First find the &lt;strong&gt;'table'&lt;/strong&gt; tag. This will grab the whole table object.&lt;br&gt;
2) Next find_all row tags as &lt;strong&gt;'tr'&lt;/strong&gt;. This will grab all rows in the table. &lt;br&gt;
3) Next find_all cell tags as &lt;strong&gt;'td'&lt;/strong&gt; per row. This will grab all cells item in each row.&lt;br&gt;
4) Sometimes the header row could be tag as &lt;strong&gt;'th'&lt;/strong&gt;. This is useful if you want to label your columns the same as the headers. &lt;/p&gt;

&lt;p&gt;I find that slowly working through each object to find my place in the HTML code was best. Many times I would index out different object to see the response and adjust accordingly. It is a pretty iterative process in the beginning and you might have to backtrack to move forward. I find that referring back to the original web page can help you find where you are in the HTML code as well. &lt;/p&gt;

&lt;p&gt;General work flow:&lt;/p&gt;

&lt;p&gt;1) Attempt to access an object/tag&lt;br&gt;
2) Count/verify # of objects&lt;br&gt;
3) See the response&lt;br&gt;
4) Verify with web page&lt;br&gt;
5) Go further into the object or repeat process.&lt;/p&gt;

&lt;p&gt;Also if you stuck with access info/ navigating use this cheatsheet. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://akul.me/blog/2016/beautifulsoup-cheatsheet/"&gt;http://akul.me/blog/2016/beautifulsoup-cheatsheet/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the code summarizing this process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tables&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nfl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;findAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'table'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# finding all tables in this soup (lucky for me only one table)
&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tables&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Checking # of tables as predicted only 1 
&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;qbr_table&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;findAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'tr'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# from that table I know look for rows 'tr' is rows in HTML
&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#Verifying how many rows I am trying to get
&lt;/span&gt;&lt;span class="n"&gt;first_row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;#Inspect one row
&lt;/span&gt;&lt;span class="n"&gt;first_row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;findAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'td'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="c1"&gt;# Looking at one row and one element 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  3) Parse and store the object.
&lt;/h2&gt;

&lt;p&gt;After you find the method to find the object and info you want in the table. Just do the same process over each row. I find that a function parse a row in combination with a list comprehension to loop over all rows is best. Below is the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;parse_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;findAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'td'&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;

&lt;span class="n"&gt;list_parsed_rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;parse_row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:]]&lt;/span&gt; &lt;span class="c1"&gt;# list_parsed_rows
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list_parsed_rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  4) Finalize the data.
&lt;/h2&gt;

&lt;p&gt;Use pandas to wrangle the data to whatever your heart desires. I find that some column had multiple information and needed to be parse out even further. &lt;/p&gt;

&lt;p&gt;Below is the result I got from web scraping ESPN for the quarterback rating (QBR) and another weather site for temperature. The QBR is normalize from 0 to 100 with 50 being the average QB score/effectiveness. In general, there seems to be a hinderance as seen from the void of high QBR at low temps. &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ozcuJkRu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jws5oo61agc24frarsxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ozcuJkRu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jws5oo61agc24frarsxh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why Data Science?</title>
      <dc:creator>Patman17</dc:creator>
      <pubDate>Fri, 06 Sep 2019 18:37:06 +0000</pubDate>
      <link>https://forem.com/patman17/why-data-science-346b</link>
      <guid>https://forem.com/patman17/why-data-science-346b</guid>
      <description>&lt;h3&gt;
  
  
  Intro &amp;amp; Background
&lt;/h3&gt;

&lt;p&gt;Hello, my name is Patrick Ly. I have been working in the oil and gas industry for 5 years. First, I held a position as an Operations Engineer which is an intermediary technical position between the office and oilfield operations. I helped improve the effectiveness and efficiency of our drilling and completions programs. Later in my career I got promoted to Site Supervisor. In this position I was responsible for managing the oilfield service equipment, asset wells, and personnel onsite in the field by delegating and facilitating the work flow. &lt;/p&gt;

&lt;p&gt;Recently this year, my company was acquired by another upstream oil company and I was laid off. In truth, it was a blessing in disguise because I contemplated quitting my position for a career shift earlier in the year. I enjoyed the people I worked with, found satisfaction in having a major impact on the business, and the monetary rewards. However, the operational side of the oil and gas industry did not stimulate my technical interests nor did I see it aligning with my long term career goals. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Search
&lt;/h3&gt;

&lt;p&gt;I started my job search to find a role that could utilize my business knowledge of the oil and gas industry but had a more technical focus. I found that a traditional drilling and completions engineer role would be the best fit from my prior experience but again the technical part of the role did not appeal to me. As an operations engineer you are primarily a project manager and then a business analyst. Thus, there is some limitation on how much higher level analysis/analytics you can do. The priority is executing and managing the operation to be within budget. &lt;/p&gt;

&lt;p&gt;As I progressed in my job search, I noticed the growing positions of jobs related to analytics and data science. This was when I did more research into this sector. One main source of information came from one of my friend that just finished a master program for data science. He talked about how relatively new it is and how the demand was growing (especially in oil &amp;amp; gas). Also he talked about the advanced applications of data science that I intrigued me. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Reason
&lt;/h3&gt;

&lt;p&gt;With this interest I began to examine the reasons I want to pursue data science. Below summarizes the main points: &lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Great fit&lt;/strong&gt; - Besides having the technical capability as an engineer, data science fits my personality as I am a very logical and analytical person that likes to look at the objectivity of the subject at hand. &lt;br&gt;
2) &lt;strong&gt;Improving technical skills&lt;/strong&gt; - Data science will improve many technical skills such as programming, statisical analysis, problem solving etc. It will provide a platform where I can become a forever learner. &lt;br&gt;
3) &lt;strong&gt;Practicality &amp;amp; scope&lt;/strong&gt; - I can envision numerous application of data science I could use not my career but personal life as well. &lt;/p&gt;

&lt;p&gt;Overall, I feel that data science could be a great way to expand my technical abilities and segue my career into another sector that I could be passionate about. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
  </channel>
</rss>
