<?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 John D Hazard on Medium]]></title>
        <description><![CDATA[Stories by John D Hazard on Medium]]></description>
        <link>https://medium.com/@jdhazard?source=rss-4af449e10b1d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*PqhCdXVITJMKCqllKLxuTw.jpeg</url>
            <title>Stories by John D Hazard on Medium</title>
            <link>https://medium.com/@jdhazard?source=rss-4af449e10b1d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:35:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jdhazard/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[f’You! You {effing} f-string!’]]></title>
            <link>https://medium.com/@jdhazard/fyou-you-effing-f-string-16f8af7fdbea?source=rss-4af449e10b1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/16f8af7fdbea</guid>
            <category><![CDATA[superheroes]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[general-assembly]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[John D Hazard]]></dc:creator>
            <pubDate>Thu, 02 May 2019 18:10:21 GMT</pubDate>
            <atom:updated>2019-05-02T18:10:21.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*AmzEyX3vql92aOf7y992Zg.jpeg" /><figcaption>You are!</figcaption></figure><p>If you came here for some hate on f-strings, you went to the wrong place. I love f-strings. Print statements are useful for building functions and seeing where we are in any given process in python. Formatted string literals, or f-strings, have the benefits of speed, simple syntax, and the ability to utilize arbitrary expressions.</p><p>Simple syntax:</p><pre>hero_name = ‘Superman’<br>secret_identity = ‘Clark Kent’<br>paramour_name = ‘Lois Lane’<br>f’Does {paramour_name} know {secret_identity} is {hero_name}?’</pre><pre>&#39;Does Lois Lane know Clark Kent is Superman?&#39;</pre><p>Pretty cool, right? Clean and simple.</p><p>Arbitrary expressions:<br>Some examples from class today.</p><pre>embedding_vector_length = 32<br>model = Sequential()<br>model.add(Embedding(top_words, embedding_vector_length, input_length=max_review_length))<br>model.add(LSTM(100))<br>model.add(Dense(1, activation=’sigmoid’))<br>model.compile(loss=’binary_crossentropy’, optimizer=’adam’, metrics=[‘acc’])<br>f’{model.summary()}’<br>model.fit(X_train, y_train, validation_data=[X_test, y_test], epochs=1, batch_size=64)</pre><p>Because the model.summary() is printed before the neural net is fitted, you can examine the summary while you wait!</p><pre>scores = model.evaluate(X_test, y_test, verbose=2)<br>f’Accuracy score is {round(scores[1]*100)}’</pre><pre>&#39;Accuracy score is 83.0&#39;</pre><p>Awesome, right? Calling those functions in the middle of a block of code was easy as heck.</p><p>Speed:</p><p>Time the performance of our print statement 10,000 times with a .format method.</p><pre>import timeit<br>timeit.timeit(“””hero_name = ‘The Flash’<br>secret_identity = ‘Wally West’<br>paramour_name = ‘Iris West’<br>‘Does {} know {} is {}?’.format(paramour_name, secret_identity, hero_name)”””, number = 10_000)</pre><pre>0.007361477008089423</pre><p>Time the performance of our print statement 10,000 times with an f-string.</p><pre>import timeit<br>timeit.timeit(“””hero_name = ‘The Flash’<br>secret_identity = ‘Wally West’<br>paramour_name = ‘Iris West’<br>f’Does {paramour_name} know {secret_identity} is {hero_name}?’”””, number = 10_000)</pre><pre>0.00228431005962193</pre><p>The Fastest Man Alive has nothing on our f-strings.</p><p>Next time you want to use a print statement or, shudder, a .format method; consider using f-strings. They’re fast, easy, and can handle some complex expressions. Now go build some effing f-strings!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16f8af7fdbea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web-Scrapin’ With Stan Lee.]]></title>
            <link>https://medium.com/@jdhazard/web-scrapin-with-stan-lee-dcb40a3605ff?source=rss-4af449e10b1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcb40a3605ff</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[marvel-comics]]></category>
            <category><![CDATA[general-assembly]]></category>
            <category><![CDATA[beautifulsoup]]></category>
            <dc:creator><![CDATA[John D Hazard]]></dc:creator>
            <pubDate>Wed, 24 Apr 2019 12:06:00 GMT</pubDate>
            <atom:updated>2019-04-24T12:06:00.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpDMbbootjSR6x_ODAx_lQ.jpeg" /><figcaption>Stanley Lieber, also know as Stan Lee, addressed his audience directly.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UlUcJEkfjrEzJAtnec2yRg.jpeg" /><figcaption>Ready for some web-scrapin’ action? Then let’s go, True Believers!</figcaption></figure><p>Extracting vast amounts of data from internet web pages can be a daunting task for any beginning data scientist. Web scraping, screen scraping, web data extraction, web harvesting makes it as easy as your favorite wall-crawler rounding up a few bad guys.</p><p>First, choose your website carefully. Be sure to check if they have an API (application programming interface) and if they don’t, make sure you take precautions not to act unethically by collecting data that doesn’t belong to you. Ask permission. In any case, make sure you design a function that scrapes data in a manner that won’t overload someone’s servers. In our case, we’ll be collecting from Stan ‘The Man’ Lee’s Wikipedia page.</p><p>Second, we’ll import our libraries.</p><pre><strong>import</strong> <strong>requests</strong><br><strong>from</strong> <strong>bs4</strong> <strong>import</strong> BeautifulSoup</pre><p>Third, we find and examine our URL: <a href="https://en.wikipedia.org/wiki/Stan_Lee">https://en.wikipedia.org/wiki/Stan_Lee</a><br>Wikipedia is a super place to scrape from because they have an easily understood URL format. <br>We’ll establish our connection to the page using the requests.get(URL) function. A status code will be given. Pay attention to these codes!</p><pre><em># Target web page:</em><br>url = &#39;https://en.wikipedia.org/wiki/Stan_Lee&#39;<br><br><em># Establishing the connection to the web page:</em><br>response = requests.get(url)<br><br><em># You can use status codes to understand how the target server responds to your request.</em><br><em># Ex., 200 = OK, 400 = Bad Request, 403 = Forbidden, 404 = Not Found.</em><br>print(&#39;Status Code: &#39;,response.status_code)<br><br><em># Pull the HTML string out of requests and convert it to a Python string.</em><br>html = response.text<br><br><em># The first 700 characters of the content.</em><br>print(&quot;<strong>\n</strong>First part of HTML document fetched as string:<strong>\n</strong>&quot;)<br>print(html[:700])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbQ3AG1AqPqfSEpX4sLA4Q.jpeg" /><figcaption>Be responsible and act ethically.</figcaption></figure><p>Create your BeautifulSoup object, inspect the website (preferably with Mozilla or Google Chrome), read the HTML code and find the useful tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXqzKUNobLBXdxAQgsPnig.jpeg" /></figure><p>Use the .find and .findall functions to pull out our text from Wikipedia. We want all the titles penned by Stan the Man!</p><pre>soup = BeautifulSoup(html, &#39;lxml&#39;)<br>marvel_comics = soup.find(&#39;div&#39;, {&#39;class&#39;: &#39;div-col columns column-width&#39;})<br>print(marvel_comics.text)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqsYU_n4OIr6gAFEzXn6kA.jpeg" /></figure><p>Iterate using Fantastic Four (For) loops. Typically, you’ll want to pull more than one item or type of item off of more than one web page. Use your vast knowledge of for loops and list comprehensions to get that information. You’ll be glad you did!</p><pre>marvel = marvel_comics.find_all(&#39;a&#39;)<br>comics_title = [(m.text) <strong>for</strong> m <strong>in</strong> marvel]<br>comics_title</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MfiAnDoRed0PKs8qzUMvqA.jpeg" /></figure><p>This post is based on a lightning talk I gave to my DSI class in early Spring of 2019. Here’s the GitHub repo with my Jupyter Notebook and Presentation.</p><p><a href="https://github.com/JDHazard/web_scraping_stan_lee">https://github.com/JDHazard/web_scraping_stan_lee</a>Da</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcb40a3605ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>