<?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 Cibele Castelo on Medium]]></title>
        <description><![CDATA[Stories by Cibele Castelo on Medium]]></description>
        <link>https://medium.com/@cibelecastelo?source=rss-93e2dd318c5d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZWm7Nc1_7N_QwMsD.</url>
            <title>Stories by Cibele Castelo on Medium</title>
            <link>https://medium.com/@cibelecastelo?source=rss-93e2dd318c5d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:30:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cibelecastelo/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[Web Scraping and Regex]]></title>
            <link>https://medium.com/@cibelecastelo/web-scraping-and-regex-9e7a90939397?source=rss-93e2dd318c5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e7a90939397</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Cibele Castelo]]></dc:creator>
            <pubDate>Tue, 01 May 2018 22:37:43 GMT</pubDate>
            <atom:updated>2018-05-01T22:51:49.960Z</atom:updated>
            <content:encoded><![CDATA[<p>Web Scraping and Regex</p><p>Hello, developers and curious. In this article, I’m going to talk about web scraping and regex. If you don’t know what web scraping is, I can resume with one sentence: “collect/extract data from web”. Yeah, that’s it. It’s very nice to write a program to do that and is very nice, too, organize the data, actually the client always gets happy with this last part. So, what I want to tell you guys is how nice and practical it is to use Regex + Pandas to organize the data that you just collected and I’m going to give an example of how you can do this. *I’m going to use python,too.</p><p>So, let’s see a sample of a dataset that I have collect from a webpage. You can see that is not clean and not organized yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*6AQ8r80vwAe1iVG5A3xILg.png" /></figure><p>The column that we want to organize is “Address”, in the first row we can see:</p><blockquote><em>“1020 Tuscaloosa Avenue, SW, Birmingham, Alabama 35211”</em></blockquote><p>and what the client want is to organize this string in four columns: ‘Street’, ’City’, ’State’ and ’ZIP’ and how can we do that? Simple, using regular expressions, pandas and python ;) For doing this task I advise you to use Pythex that is going to help you to build the regular expression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*wAERu9XpRV8IoK6yC6E-ig.png" /></figure><p>So, the regex above is capturing 4 groups. The first group is capturing everything before the first comma;the second one is capturing everything before the second comma;the third one is capturing everything except the numbers and the last one is capturing everything. And is very nice to use pythex, because you see the output.</p><p>And how can we use python to compile, use regex and create a dataframe with these four columns that we want? Is also simple:</p><p>#For this example we are going to get only the first address<br>string=str(dataframe.loc[0][‘Address’])</p><p>#compile the regex<br>regex=re.compile(‘(.*,)(.*,)(\D+)(.*)’)</p><p>#use the regex to find all matches in the string <br>data=regex.findall(string)</p><p>Finally, you can create your new dataframe:</p><ul><li>dataframe1=pd.DataFrame(data=data,columns=[‘Street’,’City’,’State’,’ZIP’],dtype=str)</li></ul><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*nmp0OB5XAvakCuOg97ak-g.png" /></figure><p>Yeah, we did it. Did you saw how easy it was? Of course, you have to study regex to do that, but a cheatsheet always can help ;). That’s it , please feel free to leave your comment about this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e7a90939397" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>