<?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 Ilkay Isik on Medium]]></title>
        <description><![CDATA[Stories by Ilkay Isik on Medium]]></description>
        <link>https://medium.com/@ilkayisik?source=rss-dbe27ddf683e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1bgdIp75VAZPZ-dc2FyB0Q.jpeg</url>
            <title>Stories by Ilkay Isik on Medium</title>
            <link>https://medium.com/@ilkayisik?source=rss-dbe27ddf683e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:41:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ilkayisik/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[Building a fully automated data pipeline with Python, MySQL and AWS]]></title>
            <link>https://medium.com/@ilkayisik/building-a-fully-automated-data-pipeline-with-python-mysql-and-aws-cb692b218b60?source=rss-dbe27ddf683e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb692b218b60</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ilkay Isik]]></dc:creator>
            <pubDate>Thu, 11 Aug 2022 14:31:58 GMT</pubDate>
            <atom:updated>2022-08-11T14:55:28.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZR5eqba9Cgh9hRJYkwKNvQ.jpeg" /><figcaption>Center Pompidou, Paris</figcaption></figure><p>As a soon-to-be data scientist I am aware of the fact that a good data scientist should also be able to perform tasks that usually falls under the job description of a data engineer (data preprocessing, ETL operations, etc). Luckily, one of the projects in the <a href="https://www.wbscodingschool.com/data-science-bootcamp/">data science bootcamp</a> I participated involved creating an automated data pipeline in the cloud that made me learn some useful data engineering skills. The purpose of this blogpost is to create a step by step documentation of the things I learned during this project (for my future self and anyone else who might be interested in doing the same).</p><h3>Project overview</h3><p>In this hypothetical project I am hired as a data scientist by an e-scooter-sharing company called Gans. Gans wants to make its scooters easily accessible to its customers in the most populous cities in Europe. To provide easy access to the scooters, Gans wants to predict e-scooter movement accurately to place them in places where they are needed the most.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KsfPpd9GDvyrsamd" /><figcaption>Photo by <a href="https://unsplash.com/@javygo?utm_source=medium&amp;utm_medium=referral">JavyGo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The goal of this project is to assemble a data pipeline which is capable of collecting the data to predict e-scooter movement from external sources in an automated way. This requires first creating a local pipeline and then moving everything to the cloud to iterate the process in an automated way. The steps to accomplish this task were the following:</p><ul><li><strong>Data collection</strong>: Using web scraping and application programming interfaces (APIs) to collect data using Python tools.</li><li><strong>Database creation: </strong>Creating a MySQL database to store the data locally and then transferring it to the cloud using Amazon Web Services (AWS) tools.</li><li><strong>Automate the pipeline:</strong> Using Lambda functions provided by AWS and setting triggers to periodically update the database with new data.</li></ul><p>Below I will elaborate each of these steps and provide code that can help you achieve something similar. (See my <a href="https://github.com/ilkayisik/python-dataengineering-pipeline">GitHub repository</a> for the complete code)</p><h4><strong>Using web scraping to collect demographical data</strong></h4><p>Web scraping is the name for fetching and extracting data that is floating around the internet and it is fairly easy to implement using the Python library <a href="https://beautiful-soup-4.readthedocs.io/en/latest/"><em>Beautiful Soup</em></a>. This library helps you to pull the contents of a webpage (as an HTML file) and parse it so that you can search and extract the information you need.</p><p>Gans needs demographical data (city name, country, and population) and Wikipedia is a great source to extract it. For this purpose I used the table that has information on <a href="https://en.wikipedia.org/wiki/List_of_European_cities_by_population_within_city_limits">European cities by population</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*isPfjXz2UVZr_vqgxL4nQg.png" /></figure><p>The code below parses the HTML content of the Wikipedia page and gives us a tree of Python objects that can be extracted for the information we need.</p><pre><strong>from bs4 import BeautifulSoup</strong><br><strong>import requests<br>import pandas as pd</strong></pre><pre>city_url=&#39;https://en.wikipedia.org/wiki/List_of_European_cities_by_population_within_city_limits&#39;</pre><pre>response = requests.get(city_url)<br>soup = BeautifulSoup(response.content, &quot;html.parser&quot;)<br>parent = soup.find(class_ = &#39;wikitable sortable&#39;)<br>children = parent.contents[1]<br>city_dict = {&quot;City&quot;: [], &quot;Country&quot;:[], &quot;Population&quot;:[]}</pre><pre>for child_ind, child in enumerate(children):<br>    if((child_ind != 0) &amp; (child_ind%2 == 0)):<br>      city_dict[&#39;City&#39;].append(child.contents[3].get_text(&quot;|&quot;,    strip=True).replace(&#39;\n&#39;,&#39;&#39;))<br>      city_dict[&#39;Population&#39;].append(child.contents[7].get_text(&quot;|&quot;, strip=True))<br>      city_dict[&#39;Country&#39;].append(child.contents[5].get_text(&quot;|&quot;, strip=True))<br>    if(child_ind == 40):<br>        break</pre><pre>cities_df = pd.DataFrame(city_dict)</pre><p>After successful execution of the code above, you should end up with a pandas dataframe like the image below, containing city and country names and the population.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*6lBKvglugPtqaXjJ0UCLAg.png" /><figcaption>Largest 10 European cities by population</figcaption></figure><h4><strong>Using an Application Programming Interface (API) to collect flight data</strong></h4><p>Gans wants to know the amount of people arriving to the cities each day to estimate the number of potential customers and whether it makes sense to make scooters available around the airports.</p><p>To collect the number of arriving flights to a city airport we will make API requests. But first you might ask: What is an API? An API is like a messenger that takes requests, tells a system (the data provider) what you want to do and returns back the information you need. We will use the API provided by <em>Aerodatabox which is available from </em><a href="https://rapidapi.com/hub">Rapid API</a>. To accomplish this step you need to sign up for an account at <a href="https://rapidapi.com/hub">Rapid API</a>, find <a href="https://rapidapi.com/aedbx-aedbx/api/aerodatabox/"><em>Aerodatabox</em></a> API, click “Subscribe to test” and choose the Basic plan that gives you 200 free requests a month. At the end of this process you will get an API key to use in your requests.</p><p><a href="https://rapidapi.com/aedbx-aedbx/api/aerodatabox/"><em>Aerodatabox</em></a> API provides different endpoints we can use. I decided to first learn icao codes of the airports using the endpoint called “<em>Search airports by freetext”.</em> It returns information on the airports if we provide the city name:</p><pre># To obtain the icao codes we use Search airports by free text<br>endpoint</pre><pre><strong>import requests</strong><br><br>url = &quot;https://aerodatabox.p.rapidapi.com/airports/search/term&quot;<br>headers = {&quot;X-RapidAPI-Key&quot;: flight_api_key,<br>           &quot;X-RapidAPI-Host&quot;: &quot;aerodatabox.p.rapidapi.com&quot;}</pre><pre>cities = list(cities_df[&quot;cities&quot;])<br><br>airport_df_list = []<br>for city_name in cities:<br>    print(city_name)<br>    querystring = {&quot;q&quot;: city_name, &quot;limit&quot;: &quot;10&quot;}<br><br>    response = requests.request(&quot;GET&quot;, url, headers=headers, params=querystring)<br>    result = response.json()<br>    temp_df = pd.json_normalize(response.json()[&#39;items&#39;]).filter([&#39;icao&#39;, &#39;iata&#39;, &#39;name&#39;, &#39;municipalityName&#39;, &#39;countryCode&#39;])<br>    airport_df_list.append(temp_df)</pre><pre># concat the dataframes in the list:airports_df = pd.concat(airport_df_list, axis=0, ignore_index=False)</pre><p>This code should give you a dataframe containing the icao codes and other data on the airports:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*nB9LInoub7qyGotVr1tigw.png" /></figure><p><strong>Now comes the part we need to automate:</strong> we can use these icao codes and tomorrow’s date in our API call with the endpoint <a href="https://rapidapi.com/aedbx-aedbx/api/aerodatabox/"><em>“FIDS/Schedules: Airport departures and arrivals”</em></a> to obtain information about the flight schedule of an airport. (The example below shows you how to do this for one airport. To see how to create a dataframe with many airports refer to my <a href="https://github.com/ilkayisik/python-dataengineering-pipeline/blob/main/version_02/gans_main_script.ipynb">GitHub repository</a>.)</p><pre><strong>from</strong> datetime <strong>import</strong> datetime, timedelta</pre><pre>to_local_time <strong>=</strong> datetime<strong>.</strong>now()<strong>.</strong>strftime(&#39;%Y-%m-%dT%H:00&#39;)<br>from_local_time <strong>=</strong> (datetime<strong>.</strong>now()<strong>+</strong>timedelta(hours<strong>=</strong>9))<strong>.</strong>strftime(&#39;%Y-%m-%dT%H:00&#39;)</pre><pre>querystring <strong>=</strong> {&quot;withLeg&quot;:&quot;true&quot;,&quot;withCancelled&quot;:&quot;true&quot;,&quot;withCodeshared&quot;:&quot;true&quot;,            &quot;withCargo&quot;:&quot;true&quot;,&quot;withPrivate&quot;:&quot;false&quot;,&quot;withLocation&quot;:&quot;false&quot;}<br><br>headers <strong>=</strong> {<br>    &#39;x-rapidapi-host&#39;: &quot;aerodatabox.p.rapidapi.com&quot;,<br>    &#39;x-rapidapi-key&#39;: flight_api_key<br>    }</pre><pre>icao_code = &quot;EDDB&quot;</pre><pre>url <strong>=</strong> f&quot;https://aerodatabox.p.rapidapi.com/flights/airports/icao/{icao_code}/{to_local_time}/{from_local_time}&quot;</pre><pre>response <strong>=</strong> requests<strong>.</strong>request(&quot;GET&quot;, url, headers<strong>=</strong>headers, params<strong>=</strong>querystring)<br></pre><p>Scooters are not the most popular way of transportation on cold and rainy days, therefore, another piece of data that needs to be collected periodically is <strong>weather data. </strong><a href="https://openweathermap.org/api">Openweather API</a> provides free weather forecasts perfectly suitable for our purposes. Again, you will have to sign up for an account and get an API key first and then make a request to obtain the forecast information.</p><pre>import requests<br>city, country = &quot;Berlin&quot;, &quot;Germany&quot;<br>OW_key = &quot;your_openweather_key&quot;</pre><pre>response<strong>=</strong>requests<strong>.</strong>get(f&#39;http://api.openweathermap.org/data/2.5/forecast/?q={city},{country}&amp;appid={OW_key}&amp;units=metric&amp;lang=en&#39;)<br>    <br>forecast_api <strong>=</strong> response<strong>.</strong>json()[&#39;list&#39;]</pre><p>A warning about the API calls: when you use the freemium plans, you have a limitation on the number of requests per month. Keep this in mind if you are working with for loops.</p><h4>Storing the data in a local MySQL database</h4><p>So far we have collected data in dataframes (cities, airports, flight schedules and the weather) and now it’s time for us to create a database to safely store all the data. I decided to use a MySQL database that requires connecting Python and MySQL using <a href="https://www.sqlalchemy.org/">SQLAlchemy</a> (a Python library that facilitates the communication between Python and relational databases). To accomplish this step you will have to set up a local <a href="https://www.simplilearn.com/tutorials/mysql-tutorial/mysql-workbench-installation">MySQL</a> instance on your computer and also make sure that SQLAlchemy is installed (“pip install SQLAlchemy” should do the trick).</p><p>To establish the connection between python and our SQL database, first go to MySQL workbench and create an empty database:</p><pre>CREATE DATABASE IF NOT EXISTS gans;</pre><p>Then establish the connection by providing the following information in python:</p><pre>schema=&quot;gans&quot; # the database you want to connect to<br>host=&quot;127.0.0.1&quot; # the location of the database server<br>user=&quot;root&quot; <br>password=&quot;your_pw&quot;<br>port=3306 # the optional database port<br>con = f&#39;mysql+pymysql://{user}:{password}@{host}:{port}/{schema}&#39;</pre><p>The “user” and “password” are the credentials to login to the database server. The “con” string is essential when using the following pandas function that connects our tables to SQL:</p><pre>city_info_df<strong>.</strong>to_sql(&#39;city_info&#39;, <br>                     con<strong>=</strong>con, <br>                     if_exists<strong>=</strong>&#39;append&#39;, <br>                     index<strong>=False</strong>)</pre><p>Here <strong>“if_exists=’append’”</strong> makes sure that next time when we run this piece of code, our tables won’t be created from scratch but will be updated with the newly added information.</p><h4>Automating the whole pipeline with Amazon Web Services</h4><p>So far we collected data from the internet, stored them in dataframes and moved them to our local SQL database. Now it is time to make sure that this process can run automatically without us being involved everyday. And this is where <a href="https://aws.amazon.com/">Amazon Web Services </a>come into play. AWS offer on-demand computing resources and services like data storage without requiring direct active management by the user, therefore, makes our lives easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*gAS4hex3FEMIe-shAVRAwQ.png" /></figure><p>To use AWS, it is necessary to <a href="https://signin.aws.amazon.com/signin?redirect_uri=https%3A%2F%2Fportal.aws.amazon.com%2Fbilling%2Fsignup%2Fresume&amp;client_id=signup&amp;code_challenge_method=SHA-256&amp;code_challenge=tetbWazWhyMrk6pGexu7cb4KejzQLwCGmP5QGv-q8Fk#/start/email">create an account </a>first. Second, we need to access Amazon Relational Database Service (Amazon RDS) to help us create a relational database instance on the cloud (in our case a MySQL instance). The third step is to create a connection between the RDS instance and the MySQL workbench platform. You can find the endpoint of your RDS database under the “connectivity and security tab” and create a new connection in MySQL Workbench, using that endpoint as the hostname.</p><p>After making sure that the connection is established between the AWS and MySQL workbench, the next step is to repeat the process of adding the dataframes to your MySQL database but this time to the one on the cloud.</p><p>To create a fully automated pipeline, we need to move our scripts to the Cloud using another AWS service called <strong>Lambda </strong>(not to be mistaken with Python’s <a href="https://www.w3schools.com/python/python_lambda.asp">lambda function</a>). Lambda is a serverless computing service that runs code and manages the underlying resources. To use lambda, first we need to create a Role, then create the lambda function, and connect our function to our RDS instance. Lambda functions also require layers to be added similar to adding modules in Python. So you need to make sure to add layers for python and SQLAlchemy. (Detailed instructions about how to accomplish these steps go beyond the scope of this post but I am planning on writing another medium article about that, so stay tuned).</p><h4>One final step: Add triggers!</h4><p>To complete our automation process we need to tell our lambda function when to run. To do that we will use <a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-rules.html">EventBridge</a>, which essentially sets a rule that triggers the execution of our scripts at certain intervals. For example, I chose the <em>Schedule expression</em> option and set it to <em>rate(1day)</em> that runs my lambda function once a day and updates my database by appending new data.</p><p>And that’s it! We managed to create our automated data pipeline on the cloud.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FFtz07proVX6Rq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fapplause-happy-excited-Ftz07proVX6Rq&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExenN2eHV1a3ZiaGhvZXp2YWc4ZXVpNnVnMjNyNjh6Znd6YzdndWo3aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FFtz07proVX6Rq%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7ad15caea6c76304039814875e7e767/href">https://medium.com/media/b7ad15caea6c76304039814875e7e767/href</a></iframe><h4>What have I learned?</h4><p>This project involved many different components including but not limited to:</p><ul><li>Collecting data from the internet with web scraping using the Python library Beautiful Soup,</li><li>Collecting data from the internet using APIs by assembling the call using the Python library requests,</li><li>Extract the necessary information using JSON files,</li><li>Clean data using Pandas,</li><li>Setting up a relational database on the cloud and populating it with data in an automatized way using Lambda functions with triggers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*axFWWAu87IIELOc7N57WLQ.png" /></figure><p>Hopefully now we collected enough information for Gans that can be used by a data scientist (in that case me again) to apply statistics, machine learning and other methods to gather some useful insights such as predicting the e-scooter movement.</p><p>All in all, this hypothetical project was great for me to learn (or let’s say be exposed to) many useful skills that a data scientist might need (even if they are officially the job of a data engineer) like collecting and cleaning data and perform ETL (extract, transform and load) operations. Hopefully, this exposure made me more prepared to confront more complex data pipelines that exist in the real world. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb692b218b60" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>