<?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 Akande Sunkanmi on Medium]]></title>
        <description><![CDATA[Stories by Akande Sunkanmi on Medium]]></description>
        <link>https://medium.com/@sunkie007?source=rss-9e3acc215fff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U1mvZL7mi2fuGHAndZGq7Q@2x.jpeg</url>
            <title>Stories by Akande Sunkanmi on Medium</title>
            <link>https://medium.com/@sunkie007?source=rss-9e3acc215fff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:27:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunkie007/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[Webscraping Formula One (F1) Legends records using BeautifulSoup & Requests.]]></title>
            <link>https://medium.com/@sunkie007/webscraping-formula-one-f1-legends-records-using-beautifulsoup-requests-1040f5afeb18?source=rss-9e3acc215fff------2</link>
            <guid isPermaLink="false">https://medium.com/p/1040f5afeb18</guid>
            <category><![CDATA[beautifulsoup]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[request]]></category>
            <dc:creator><![CDATA[Akande Sunkanmi]]></dc:creator>
            <pubDate>Sun, 21 Jan 2024 23:39:07 GMT</pubDate>
            <atom:updated>2024-01-22T10:22:47.492Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7eS6dEFjFKHk4qLG" /></figure><p>Formula One (<strong>F1</strong>) legends are revered figures in the world of motorsport, celebrated for their extraordinary skill, tenacity, and achievements in the pinnacle of racing — Formula One. Over the years, F1 has produced a lineage of iconic drivers who have left an indelible mark on the sport. These legends are not only distinguished by their numerous victories and championship titles but also by their impact on the evolution of racing and the sport’s global popularity.</p><p>In this project i will be testing webscraping skills i just learnt on python. I will be using the Google Colab IDE for my analysis.</p><p>The data was scrapped <a href="https://www.gpfans.com/en/f1-legends/">here</a>.</p><p><strong>Analysis:</strong></p><pre>from bs4 import BeautifulSoup<br>import requests<br>import pandas as pd<br><br>url = &#39;https://www.gpfans.com/en/f1-legends/&#39;<br>page = requests.get(url)<br>soup = BeautifulSoup(page.text, &#39;html&#39;)<br>print(soup.prettify())</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3f4YK7fuB1vQNUMSNGikHg.png" /></figure><p>I loaded the necessary libraries <strong>BeautifulSoup</strong>, R<strong>equests</strong> and <strong>Pandas. </strong>Next is to pass the web-page into a variable — <strong>url</strong>, then pass the result of the HTML requests into another variable — <strong>page.</strong> Then, the BeautifulSoup library will assist with ensuring we can search html tags for necessary information we desire to obtain from our html text as seen above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fDKI_qrTrvt25cjeUDgklQ.png" /><figcaption>Inspecting the page for HTML tags</figcaption></figure><p>The HTML script that contains the tags needed is within the tag that has &lt;table id=”allLegends”&gt;. I used the <strong>soup.find_all</strong>function to get the tags which contains, &lt;<strong>thead</strong>&gt;, &lt;<strong>td</strong>&gt;, &lt;<strong>tr</strong>&gt; tags for our extraction. Then, passed the result into a variable <strong>legend_details.</strong></p><pre>soup.find_all(&#39;table&#39;, id=&quot;allLegends&quot;)<br>legend_details = soup.find_all(&#39;table&#39;, id=&quot;allLegends&quot;)<br>print(legend_details)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlJ629jaQzjClN9bbJrMbw.png" /></figure><p>From the screenshot above, you can see the various tags of interest (&lt;<strong>thead</strong>&gt;, &lt;<strong>tr</strong>&gt;, &lt;<strong>td</strong>&gt;).</p><p>Next, is to get the table headers (<strong>Name, Nationality, Debut, Last race, Races, Podiums, Won, Championships, Won %, Profile</strong>).</p><pre>soup.find_all(&#39;td&#39;)[:10]<br>world_drivers = soup.find_all(&#39;td&#39;)[:10]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Em9CUjXx5G2G4pSdtpF5sg.png" /></figure><p>The <strong>soup</strong> function searched for all &lt;<strong>td</strong>&gt; tags then extracted only the first 10 results [<strong>:10</strong>] which was stored as a variable — <strong>world_drivers.</strong></p><pre>world_drivers_title = [title.text.strip() for title in world_drivers]<br>print(world_drivers_title)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*II9BmeHkD_SGliRAvIxegQ.png" /></figure><p>From the &lt;td&gt; tag which housed the header tags, i extracted individual headers (lists) from the result through looping. i.e look into the world_drivers variable and bring our each element. {<em>for</em> <strong>title</strong> <em>in</em> <strong>world_drivers</strong>}, the result was the stored in another variable — <strong>world_drivers_title.</strong></p><p>The next thing is to pass the list into a <strong><em>pandas</em></strong> DataFrame.</p><pre>pd.DataFrame(columns = world_drivers_title)<br>df4 = pd.DataFrame(columns = world_drivers_title)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uOLKluUcJeiMOXKZNdT5tQ.png" /></figure><p>Our table headers is ready and the <strong>Pandas DataFrame</strong> has been assigned to a variable called <strong>df4.</strong>Next will be to use loops and iterations to load the scrapped table tags &lt;<strong>td</strong>&gt; into the headers.</p><p>The next thing to do is to scrape data individually for each columns &lt;<strong>tr</strong>&gt; tags, this can be gotten using this code:</p><pre>soup.find_all(&#39;tr&#39;)[1:]<br>table1 = soup.find_all(&#39;tr&#39;)[1:]</pre><p>The code is saying look for all &lt;<strong>tr</strong>&gt; tags on the HTML text, then get everything except the first result i.e [1:]. The result is then assigned to a variable called <strong>table1.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UmB9LvKNs1hoEgGlBVBqyA.png" /></figure><p>Next is to use loops and iterations to search all &lt;td&gt; tags and input them into our headers.</p><pre>for row in table1:<br>  row_data = row.find_all(&#39;td&#39;)<br>  each_row_data = [title.text.strip() for title in row_data]<br>  # print(each_row_data)<br><br>  length = len(df4)<br>  df4.loc[length] = each_row_data</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVbX-L9rWn8Ms5fojrJBIA.png" /></figure><p>The code says go into <strong>table1</strong> get all items with &lt;td&gt; tag then assign them to a variable — <strong>row_data. </strong>Then, unnecessary character attached to the result from each tags should be stripped should it appear hence the <strong>text.strip() </strong>function and the cleaned result should be saved into a variable called <strong>each_row_data. &lt;length = len(df4)&gt; </strong>ensures the number of columns from the <strong>df4 </strong>DataFrame matches the result we would get from extracting all the &lt;<strong>td</strong>&gt; tags. <strong>df4.loc[length] = each_row_data </strong>this line of code says all we extracted &lt;td&gt; tags goes under the header/columns appropriately using the <strong>.loc[leghth] </strong>function.</p><p>I thoroughly enjoyed this project. I am looking forward to part 2 of this series, where result obtained will be taken to SQL and PowerBI for further analyis and insights.</p><p>Thank you, I look forward to your comment, corrections and claps :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1040f5afeb18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Capstone Project: Cyclistic bike-share analysis case study (drivvy tripdata)]]></title>
            <link>https://medium.com/@sunkie007/google-capstone-project-cyclistic-bike-share-analysis-case-study-drivvy-tripdata-fda061d0d98f?source=rss-9e3acc215fff------2</link>
            <guid isPermaLink="false">https://medium.com/p/fda061d0d98f</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Akande Sunkanmi]]></dc:creator>
            <pubDate>Sat, 23 Sep 2023 22:56:29 GMT</pubDate>
            <atom:updated>2023-09-26T13:23:45.060Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*annxKZfTBpqk4oEs" /><figcaption>Photo by <a href="https://unsplash.com/@cathus?utm_source=medium&amp;utm_medium=referral">Garry Nesam</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>I recently completed the Google Data Analytics Specialization course and earned my Professional Certificate, and I have been tasked to complete a Capstone Project highlighting the technical skills I learned during the course. The case I chose to analyze for my Capstone Project is the Cyclistic bike-share case study- data was provided by drivvy tripdata.</p><h3><strong>Background</strong></h3><p>Cyclistic launched a bike-share offering service in 2016. It has grown to a fleet of over 5,824 bicycles that are geo-tagged and locked into a network of over 692 stations across Chicago. Cyclistic marketing has relied heavily on general awareness to drive patronage across customer segments. Cyclistic finance analyst believe annual members tends to be more profitable compared to casual riders. Lily Moreno the director of marketing believes there should be a means to convert casual riders to annual members to increase profitability, the clear goal is conversion of casual riders to annual members.</p><h3>Business task</h3><p>I have been tasked a junior analyst to create a report based on existing historical data to show how annual members and casual riders use Cyclistic bike-share services differently by providing analysis of the bike-share service, supporting my analysis with visualization and key findings as well as provide three top recommendations based on my analysis.</p><h3>Data Wrangling and Cleaning</h3><p>Data wrangling is an essential step in the data analysis process because the quality of the insights derived from data largely depends on the quality of the data itself. Wrangling ensures that data is accurate, complete, and formatted correctly, making it easier for analysts and data scientists to draw meaningful conclusions from it.</p><p>The dataset was sourced <a href="https://divvy-tripdata.s3.amazonaws.com/index.html">here</a>. It consist of rider’s data for 12 months from January — December 2022. I will be doing a preliminary check on the dataset for proper understanding and data wrangling will be deployed so as to make sense of the analysis. Microsoft SQL Server Management studio will be used for analysis of the data and visualization will be presented using Power BI.</p><ol><li><strong>A quick look at the table schema:</strong></li></ol><pre>--the table schema showing the data_types<br>SELECT  COLUMN_NAME, <br>        DATA_TYPE<br>FROM INFORMATION_SCHEMA.COLUMNS</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*zbDRcL8pUtWrnrFq0tRB8Q.png" /></figure><blockquote>For our exploratory analysis we discovered some data-type of some columns are not in the appropriate format hence the need to convert them to the appropriate format, particularly the <strong>started_at</strong>, <strong>ended_at</strong> columns.</blockquote><p><strong>2. Getting the Total number of records from our dataset:</strong></p><pre>--Number of Records<br>SELECT COUNT(*) AS &#39;Number of Records&#39;<br>FROM cyclist_tripdata</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*KmKoK9VswKe3pRx6d2YdqQ.png" /></figure><blockquote>The data consist of 5,667,717 records, however we must ensure that the records are not duplicated. The <strong>rider_id </strong>is the unique key and must not be duplicated or have null value. To ensure accuracy I will investigate the column and ensure any inaccuracy is corrected.</blockquote><p><strong>3. Checking for duplicates</strong></p><pre>--Checking if the primary key ride_id has duplicates<br>SELECT ride_id, count(ride_id) AS Count<br>FROM cyclist_tripdata<br>GROUP BY ride_id<br>HAVING count(ride_id)&gt;1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*t6WuSXvpaVFfJJKHwJODCg.png" /></figure><blockquote>Investigation shows the primary key has duplicates, so we have to remove the duplicate records, leaving the unique ones for analysis.</blockquote><pre>--Deleting the duplicates in the ride_id column<br>WITH CTE AS (<br> SELECT *,<br>   ROW_NUMBER() OVER(PARTITION BY ride_id ORDER BY ride_id) AS Duplicated_rows<br>FROM cyclist_tripdata)<br>DELETE FROM CTE WHERE Duplicated_rows &gt; 1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*SrYERFGpVVoEE-D58_qFvw.png" /></figure><p><strong>4. Checking for null values in the data</strong></p><pre>--getting null count for each columns<br>SELECT &#39;ride_id&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE ride_id is null<br>UNION<br>SELECT &#39;rideable_type&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE rideable_type is null<br>UNION<br>SELECT &#39;started_at&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE started_at is null<br>UNION<br>SELECT &#39;ended_at&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE ended_at is null<br>UNION<br>SELECT &#39;start_station_name&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE start_station_name is null<br>UNION<br>SELECT &#39;start_station_id&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE start_station_id is null<br>UNION<br>SELECT &#39;end_station_name&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE end_station_name is null<br>UNION<br>SELECT &#39;end_station_id&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE end_station_id is null<br>UNION<br>SELECT &#39;start_lat&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE start_lat is null<br>UNION<br>SELECT &#39;start_lng&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE start_lng is null<br>UNION<br>SELECT &#39;end_lat&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE end_lat is null<br>UNION<br>SELECT &#39;end_lng&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE end_lng is null<br>UNION<br>SELECT &#39;member_casual&#39; as ColumnName, COUNT(*) as NullCount<br>FROM [dbo].[cyclist_tripdata]<br>WHERE member_casual is null</pre><blockquote>The result shows:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*6IhNfBrAg69aX4NwhErVDg.png" /><figcaption>Image showing count of nulls in each columns</figcaption></figure><blockquote>For this analysis our primary key (<strong>ride_id</strong>) has no null value as well as <strong>rideable_type</strong>, <strong>started_at</strong>, <strong>ended_at </strong>and <strong>member_casual, </strong>therefore we will not be deleting null values as they will not be impacting our analysis, thereby making our assessment more robust.</blockquote><p><strong>5. Checking for correctness of the dataset</strong></p><pre>--Delecting records where started_at column is greater than ended_at<br>DELETE FROM [dbo].[cyclist_tripdata]<br>      WHERE [started_at] &gt; [ended_at]</pre><p>There are records where the trip start time is greater than when the trip ended, hence the need to delete them so as to ensure accuracy of our analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*kwOfMmfT7RUCL9uUOrWJNQ.png" /></figure><p><strong>6. Renaming column</strong></p><p>Column <strong>member_casual </strong>will be renamed to <strong>membership_type</strong>, and <strong>rideable_type </strong>to <strong>bike_type</strong>, so has to differentiate between the types of membership riders have.</p><pre>--renaming column member_casual to membership_type<br>sp_rename &#39;cyclist_tripdata.member_casual&#39;, &#39;membership_type&#39;<br><br>--renaming column rideable_type to bike_type<br>sp_rename &#39;cyclist_tripdata.rideable_type&#39;, &#39;bike_type&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0JnO11Yp9gpYWVUbdlNx-g.png" /></figure><p>Both column has been renamed successfully to membership_type and bike_type.</p><h3>Analysis process</h3><p>I will be going further to check the distinct type of <strong>bike_type</strong>. There are 3 types of bikes in our analysis, electric bikes, classic bikes and docked bikes.</p><pre>--checking the distinct count of bikes<br>SELECT DISTINCT bike_type<br>FROM [dbo].[cyclist_tripdata]<br><br>--checking the distinct count of membership_type<br>SELECT DISTINCT membership_type<br>FROM [dbo].[cyclist_tripdata]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*MY4l5bjFbF9uzZlsbgC_Mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*mgTQvrxCq1x6DlFiZYzwfA.png" /></figure><p>I created a new column trip_duration in minutes (<strong>trip_duration_m</strong>)</p><pre>--create a new column as trip duration<br>ALTER TABLE [dbo].[cyclist_tripdata]<br>  ADD trip_duration_m int <br><br>--Updated trip duration in minutes column<br>UPDATEcyclist_tripdata<br>SET[trip_duration_m] = DATEDIFF(minute, [started_at], [ended_at])<br>   WHERE DATEDIFF(minute, [started_at], [ended_at]) &gt; 1<br>   AND DATEDIFF(HOUR, [started_at], [ended_at]) &lt; 24;</pre><p>I updated the <strong>trip_duration_m</strong> column to show the duration of the trips taken in minutes greater than 1 minute and within 24hours.</p><p>Going further into the analysis i will be adding few columns which will enrich our analysis, <strong>day_of_week</strong>, <strong>rides_in_month</strong>, <strong>time_of_the_day</strong>, <strong>ride_route, hour_of_the_day</strong>.</p><pre>--Adding new columns to the dataset<br>ALTER TABLE [dbo].[cyclist_tripdata]<br>ADD day_of_week nvarchar(50),<br>    rides_in_month nvarchar(50),<br>    time_of_the_day nvarchar(50),<br>    ride_route nvarchar(max),<br>    hour_of_the_day nvarchar(50);<br><br><br>--Updating the extracted day_of_week<br>UPDATE [dbo].[cyclist_tripdata]<br>SET day_of_week = <br>                CASE WHEN DATEPART(WEEKDAY, [started_at]) = 1 THEN &#39;SUNDAY&#39; <br>                     WHEN DATEPART(WEEKDAY, [started_at]) = 2 THEN &#39;MONDAY&#39;<br>                     WHEN DATEPART(WEEKDAY, [started_at]) = 3 THEN &#39;TUESDAY&#39;<br>                     WHEN DATEPART(WEEKDAY, [started_at]) = 4 THEN &#39;WEDNESDAY&#39;<br>                     WHEN DATEPART(WEEKDAY, [started_at]) = 5 THEN &#39;THURSDAY&#39;<br>                     WHEN DATEPART(WEEKDAY, [started_at]) = 6 THEN &#39;FRIDAY&#39;<br>                     ELSE &#39;SATURDAY&#39; <br>                END;<br><br>--Updating the extracted month<br>UPDATE [dbo].[cyclist_tripdata]<br>SET [rides_in_month] = CASE WHEN MONTH([started_at]) = 1 THEN &#39;JANUARY&#39;<br>                       WHEN MONTH([started_at]) = 2 THEN &#39;FEBRUARY&#39;<br>                       WHEN MONTH([started_at]) = 3 THEN &#39;MARCH&#39;<br>                       WHEN MONTH([started_at]) = 4 THEN &#39;APRIL&#39;<br>                       WHEN MONTH([started_at]) = 5 THEN &#39;MAY&#39;<br>                       WHEN MONTH([started_at]) = 6 THEN &#39;JUNE&#39;<br>                       WHEN MONTH([started_at]) = 7 THEN &#39;JULY&#39;<br>                       WHEN MONTH([started_at]) = 8 THEN &#39;AUGUST&#39;<br>                       WHEN MONTH([started_at]) = 9 THEN &#39;SEPTEMBER&#39;<br>                       WHEN MONTH([started_at]) = 10 THEN &#39;OCTOBER&#39;<br>                       WHEN MONTH([started_at]) = 11 THEN &#39;NOVEMBER&#39;<br>                       ELSE &#39;DECEMBER&#39;<br>                       END;<br>--Updating the extracted time of day<br>UPDATE [dbo].[cyclist_tripdata]<br>SET [time_of_the_day] = CASE<br>       WHEN DATEPART(HOUR, [started_at]) &gt;= 6 AND DATEPART(HOUR, [started_at]) &lt; 12 THEN &#39;Morning&#39;<br>       WHEN DATEPART(HOUR, [started_at]) &gt;= 12 AND DATEPART(HOUR, [started_at]) &lt; 18 THEN &#39;Afternoon&#39;<br>       ELSE &#39;Night&#39;<br>      END<br><br>--Updating ride route<br>UPDATE [dbo].[cyclist_tripdata]<br>SET [ride_route] = CONCAT([start_station_name], &#39; &lt;==&gt; &#39;, [end_station_name])<br>                   WHERE [start_station_name] IS NOT NULL AND [end_station_name] IS NOT NULL<br><br>--Updating hour of the day<br>UPDATE [dbo].[cyclist_tripdata]<br>SET hour_of_the_day = CASE<br>                        WHEN DATEPART(HOUR, [started_at]) = 0 THEN &#39;12 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 1 THEN &#39;1 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 2 THEN &#39;2 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 3 THEN &#39;3 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 4 THEN &#39;4 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 5 THEN &#39;5 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 6 THEN &#39;6 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 7 THEN &#39;7 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 8 THEN &#39;8 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 9 THEN &#39;9 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 10 THEN &#39;10 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 11 THEN &#39;11 AM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 12 THEN &#39;12 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 13 THEN &#39;1 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 14 THEN &#39;2 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 15 THEN &#39;3 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 16 THEN &#39;4 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 17 THEN &#39;5 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 18 THEN &#39;6 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 19 THEN &#39;7 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 20 THEN &#39;8 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 21 THEN &#39;9 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 22 THEN &#39;10 PM&#39;<br>                        WHEN DATEPART(HOUR, [started_at]) = 23 THEN &#39;11 PM&#39;<br>                       END;<br><br><br><br></pre><p><strong>Insight </strong>#1<strong>:</strong></p><p>I checked for the count of trips between both riders. Then looked at the count of rides by casual rider’s and Annual member’s of the bike-share service.</p><pre>-- Count of rides by annual members and casual riders<br>SELECT &#39;casual&#39; AS MembershipType, COUNT(ride_id) AS CountOfTrips<br>FROM [dbo].[cyclist_tripdata]<br>WHERE [membership_type] = &#39;casual&#39;<br>UNION<br>SELECT &#39;member&#39; AS MembershipType, COUNT(ride_id) AS CountOfTrips<br>FROM [dbo].[cyclist_tripdata]<br>WHERE [membership_type] = &#39;member&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*qiPw9mSjLh4zmMgECeOHQQ.png" /></figure><blockquote>Result shows that:</blockquote><blockquote>Annual Members (<strong>3,345,634</strong>) took more rides compared to Casual riders (<strong>2,321,978</strong>) within the duration of the time covered.</blockquote><p><strong>Insight #2:</strong></p><p>Looking at the average rides in minutes for both users of the bike-sahre service.</p><pre>--Average ride minutes for casual riders and annual members<br>SELECT &#39;casual&#39; AS MembershipType, AVG([trip_duration_m]) AS AverageTripDurationInMinutes<br>FROM [dbo].[cyclist_tripdata]<br>WHERE [membership_type] = &#39;casual&#39;<br>UNION<br>SELECT &#39;member&#39; AS MembershipType, AVG([trip_duration_m]) AS AverageTripDurationInMinutes<br>FROM [dbo].[cyclist_tripdata]<br>WHERE [membership_type] = &#39;member&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*gBhTd_OwkkHRm7dYBwPI0w.png" /></figure><blockquote>Result shows that:</blockquote><blockquote>Casual riders average 29minutes <strong>i.e </strong>more than double of annual members. while Annual members averaged 12minutes within the duration of the time covered.</blockquote><p><strong>Insight #3:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*tPWq_O9EqQnGXZin9XIKpg.png" /></figure><blockquote>Looking at the Average trips by the hour, it clear Annual members takes more rides by he hour than Casual members. Annual Member has two peak period’s 8am and 5pm, suggesting they use the bike-share service as a means of transportation as most businesses operates between (8am-5pm). For Casual riders the peak-period is 5pm in the evening, suggesting they ride for leisure or sporting activity.</blockquote><p><strong>Insight #4:</strong></p><p>What is the preferred bike choice for the different riders?</p><pre>--looking at the preferred choice of bike among both riders<br>SELECT &#39;Annual Member&#39; AS Membership_Type, COUNT(ride_id) AS Count_of_Rides, bike_type<br>FROM cyclist_tripdata<br>WHERE membership_type = &#39;member&#39;<br>GROUP BY bike_type<br>UNION ALL<br>SELECT &#39;Casual Member&#39; AS Membership_Type, COUNT(ride_id) AS Count_of_Rides, bike_type<br>FROM cyclist_tripdata<br>WHERE membership_type = &#39;casual&#39;<br>GROUP BY bike_type</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*SQrebeeyYVSITscZqeahJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WGONEbpvmlrjomRy6e-5XQ.png" /></figure><blockquote>Result shows that:</blockquote><blockquote><strong>Annual members</strong> completed more rides using <strong>classic_bikes </strong>(<strong>1,709,737</strong>) than <strong>Casual riders </strong>(<strong>891,440</strong>). Similarly, <strong>Annual members </strong>completed more rides using <strong>electric_bikes</strong> (<strong>1,635,897</strong>) compared to <strong>Casual riders </strong>(<strong>1,253,064</strong>). Only <strong>Casual riders </strong>used the<strong> docked_bikes </strong>with only<strong> 177,474 rides</strong>.</blockquote><p><strong>Insight #5:</strong></p><p>Time of the Day showing riders activity</p><pre>--Showing the count of rides by day of the week and its percentage<br>SELECT <br>    COUNT(ride_id) AS ride_count,<br>    day_of_week,<br>    CAST(COUNT(ride_id) * 100.0 / SUM(COUNT(ride_id)) OVER () AS DECIMAL(18, 2)) AS &#39;% of total rides&#39;<br>FROM [dbo].[cyclist_tripdata]<br>GROUP BY day_of_week<br>ORDER BY ride_count DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*KaGUncHWm-TieL10283paA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZOBKCmFws1mcKhOUAK1sg.png" /></figure><blockquote>Result shows that:</blockquote><blockquote>More rides takes place in the <strong>Afternoon </strong>compared to <strong>Night </strong>and <strong>Morning. 43.61% </strong>of rides takes place in Afternoon, while <strong>32.61%</strong> and <strong>23.78% </strong>of rides takes place <strong>Night </strong>and <strong>Morning </strong>respectively. We can deduce that more economic activities happens during the Afternoon suggesting riders use the bike-share service as a means of transportation, while people ride in the night probably for leisure.</blockquote><p><strong>Insight #6:</strong></p><p>What is the trend of rides by Day of the week?</p><pre>--Showing the count of rides by day of the week and its percentage <br>SELECT <br>    COUNT(ride_id) AS ride_count,<br>    day_of_week,<br>    CAST(COUNT(ride_id) * 100.0 / SUM(COUNT(ride_id)) OVER () AS DECIMAL(18, 2)) AS &#39;% of total rides&#39;<br>FROM [dbo].[cyclist_tripdata]<br>GROUP BY day_of_week<br>ORDER BY ride_count DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*zcoyKi6-jhSqox1ljHNEXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*piijQSObyX5jtCEGbe9evA.png" /></figure><blockquote>Result shows that:</blockquote><blockquote><strong>Saturday </strong>and <strong>Thursday </strong>appears to the days with the highest count of rides with takes <strong>16.17% </strong>and <strong>14.85% </strong>respectively, while <strong>Monday</strong>, has the least frequent rides.</blockquote><p><strong>Insight #7:</strong></p><p>What time of the year are both riders most and least active?</p><pre>--showing rides per month<br>SELECT count(ride_id) AS ride_count, rides_in_month<br>FROM [dbo].[cyclist_tripdata]<br>GROUP BY rides_in_month<br>ORDER BY ride_count desc; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*6TWAB4X0Jo0eISZkQtdV3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JcChSPl2xtbtxy8yqUYWTQ.png" /></figure><blockquote>Result shows that:</blockquote><blockquote><strong>July, August and June</strong> are the months with the highest number of trips accounting for <strong>2,378,578 rides </strong>i.e <strong>41.9% </strong>in the year. Compared to the months where lower rides was observed (<strong>December, January and February</strong>) accounting for <strong>401,180 rides</strong> i.e <strong>7.1%</strong>. This shows that more rides occurs in the Summer than Winter seasons.</blockquote><p><strong>Insight #8:</strong></p><pre>--Top 20 frequent ride route<br>SELECT TOP 20 ride_route, COUNT(*) AS frequency <br>FROM [dbo].[cyclist_tripdata]<br>WHERE ride_route IS NOT NULL<br>GROUP BY ride_route<br>ORDER BY frequency DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urBRRtG-QshwyeDVApXNZA.png" /></figure><blockquote>Result shows that:</blockquote><blockquote>From the <strong>Top 20 Trips</strong> between both riders, <strong>7 </strong>of them are “<strong>round trips” </strong>with the same start and end stations. About <strong>18,489 rides</strong> started at <strong>Streeter Dr &amp; Grand Ave </strong>while most trips ended at <strong>DuSable Lake Dr </strong>with a count of <strong>14,030 trips.</strong></blockquote><p><strong>Recommendation</strong></p><p>Based on the revelation from the analysis of the bike share analysis, the following recommendations should be adopted:</p><ol><li><strong>Targeted marketing strategy:</strong> There should be a deliberate ad target at the start and end stations with high frequency, such as Streeter Dr. and Grand Ave., DuSable Lake Shore Dr. and Monroe St., Ellis Ave. and 60th St., Ellis Ave. and 57th St., and University Ave. and 57th St. Also, there’s a need to craft a marketing campaign designed to resonate with casual members so as to convert them to an annual membership. Implementation of referral programs to reward annual members who refer friends and colleagues to join has the potential to grow the annual membership base. The business should adopt a partnership model where they collaborate with local businesses, organizations, and schools so they can promote the use of the cyclistic bicycle-share business. The use of social media, email marketing, and blogs in promotion of discounts will go a long way toward growing the annual user bracket.</li><li><strong>Pricing:</strong> Casual riders should be offered a discount to become annuals after a limited amount of time on the bike-share platform in the form of flash sales or when they are on the check-out page during pay-as-you-go payments. Handing out souvenirs to casual riders who purchase annual membership during the discount flash sales will likely increase the uptake of annual membership. There should be free sign-up codes that waive a 50 percent discount when a specific number of rides has been reached. There should be a trial period where casual riders get to enjoy the benefits of annual membership for a limited time as a means of attraction to becoming an annual member. The introduction of badges, rewards, and group leaderboards will improve ride frequency, and this will be tied to rewards such as ride credits or exclusive perks for annual members who ride frequently.</li><li><strong>Market survey:</strong> The business should develop a survey via email to casual riders so as to understand where improvements can be made or what features they expect to enjoy should they take up the annual membership. Through a market survey, we can determine the actual users of the bike-share service. Information about the age demographics of casual riders will be useful in tailoring ads to specific age groups, which will drive increased uptake for annual membership. Through market surveys, we tend to gain insights into why casual users are hesitant to become annual members. This can help tailor the marketing and pricing strategies accordingly. Also, through a market survey, we get to understand the common pain points related to available bike-station location networks, the availability of different types of bikes, or payment issues so as to improve service delivery.</li></ol><p>Please Click <a href="https://app.powerbi.com/view?r=eyJrIjoiYzIxYThmMmEtOGM3Ny00NTY4LTk4ZDYtNGJhY2Q5NzM0ZDAyIiwidCI6IjM0N2I3NmJiLWRmZDAtNGExMy1hYTk1LTg2OTc4ZGI4ZDNmNiJ9"><strong>here</strong></a><strong> </strong>to see <strong>PowerBi Visualization:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tpj1xm5OYhbXBLGkSG2BPQ.png" /></figure><p>Please click <a href="https://github.com/sunkie007/sunkanmi-google-capstone-cyclistic-project.git"><strong>here</strong></a><strong> </strong>for GitHub documentation. Thank you for you time. Looking forward to your comments, claps and feedback!! Till next time :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fda061d0d98f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Exploratory Data Analysis (EDA) of crime data in the Uk (June-Dec 2022).]]></title>
            <link>https://medium.com/@sunkie007/an-exploratory-data-analysis-eda-of-crime-data-in-the-uk-june-dec-2022-2f392e191b71?source=rss-9e3acc215fff------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f392e191b71</guid>
            <dc:creator><![CDATA[Akande Sunkanmi]]></dc:creator>
            <pubDate>Thu, 13 Apr 2023 12:46:15 GMT</pubDate>
            <atom:updated>2023-04-18T19:09:18.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*EKDBA1W-3N5y2XQrNxo8ag.jpeg" /><figcaption>Image from Google.</figcaption></figure><p>This project aims to do an exploratory analysis of crime in the UK within the specified period of June to December 2022. The investigation is intended to reveal insights that will be helpful for policymakers and the public. I will be showing how the data was sourced, merged into a single file, and imported into MSSMS as a single file. Then answer some basic questions based on the information from our dataset.</p><p><strong>Data Collection</strong></p><p>The data was sourced from the official UK government website where crime data is collated and reported. Please click <a href="https://data.police.uk/data/">here</a> to download dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylkh3CYgu9J_D3AkPFhSrw.png" /><figcaption>Data was sourced at the Uk Government site on crime.</figcaption></figure><p>I downloaded the dataset and then grouped them into a single file, as it was collected monthly in CSV format. I used the CMD command below to combine the multiple files into a single one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iux76LL1MeV0PRE8bZbKRg.png" /><figcaption>An image showing how to merge multiple CSV files into one file using CMD.</figcaption></figure><p>The next step is to import our data into Microsoft SQL Server Management studio (MSSMS) where we will be doing our exploratory data analysis.</p><p>The CSV files were loaded into the MSSMS tool for analysis; the image below shows how the file was uploaded for our analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBAIekB7qDeXv2lQ54K_aQ.png" /><figcaption>The image shows how the dataset was loaded into MSSMS</figcaption></figure><p>A quick preview of our dataset shows we have <strong>3,684,808</strong> records (rows) and <strong>12</strong> columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HIogu46CdX1ge_9emMclWg.png" /><figcaption>Image showing our data set has 3,684,808 rows</figcaption></figure><p>Our dataset has <strong>12</strong> columns, as seen in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZuBKma9bnMKiW6yiVvljTg.png" /><figcaption>The image showing our dataset has 12 columns.</figcaption></figure><p>With a dataset this huge, we can obtain an enormous amount of insight from it and use different queries to answer different questions. Having seen what our dataset looks like at a glance, we can begin working on it. The next step is data cleaning; this is to ensure we are working with clean data for accuracy and completeness.</p><p><strong>Data Cleaning</strong></p><p>Data cleaning is the process of identifying and fixing errors in a dataset, such as <em>nulls</em>, inaccurate data types, duplicates, and missing data. The importance of cleaning a dataset cannot be overemphasized because it is an important step in data analysis as it ensures accuracy, consistency, and the absence of bias. If we are able to achieve this (<strong>data cleaning</strong>), the result can be used to produce useful insights for management decisions.</p><p>First, we will be checking each column for <em>nulls </em>and <em>duplicates </em>and deleting columns irrelevant to our analysis.</p><p>Looking at the <strong>Crime_ID</strong> column, I discovered there are about <strong>636,052</strong> <em>null </em>values for <strong>Crime_ID</strong>, we will be deleting the <em>null </em>columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Itq51zse5d442C0aDkZ-tQ.png" /></figure><p>After deleting the <em>null </em>values this is what we have below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*P8xm6rOzNvlPuKa3G-lpTQ.png" /></figure><p>This was done for all columns in our dataset, and where <em>nulls </em>appeared, they were deleted until each column was free of <em>null </em>values. I further proceeded to check if there were duplicate values in the <strong>Crime_ID</strong> column, as this is expected to be unique; some of the records were duplicated, hence must be eliminated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o87e_vVuFMdW63zYg_JYUg.png" /></figure><p>This is the result after duplicates were eliminated. About <strong>38,417</strong> rows were removed as this was duplicated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fdj6QjGsoL7UqMapCwbueQ.png" /></figure><p>Each column was investigated for nulls, and where they were found, they were deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*lNWK1MXE4mBUp7KxVorZWw.png" /></figure><p>Once all <em>nulls </em>had been eliminated, I renamed the <strong><em>Reported_by</em></strong> column to <strong><em>Police_Unit.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C5fzP5e_G6H5SOiNfuofig.png" /></figure><p>The next step is to drop columns that are not needed for our analysis. The <strong>Falls_within</strong>, <strong>LSAO_code</strong>, <strong>LSAO_name,</strong> and <strong>Context</strong> will be dropped from our table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iclEN9nlBJuPumMFsQ0iQA.png" /><figcaption>Image showing deleted columns</figcaption></figure><p>What our table looks like after data cleaning</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8Y2puHNC-Qg7-k-a6rM-A.png" /></figure><p>What we have now is <strong>2,984,743 records </strong>and <strong>8 columns</strong> for our analysis. We can go ahead and start our exploratory data analysis.</p><p><strong>Exploratory Data Analysis</strong></p><p>Our investigation begins with how many police units we have in the dataset. The result shows there are <strong>43 police units</strong> in our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bI1sdSnrs-QZeamHhlN_lg.png" /></figure><p>I then proceeded to check the different types of crime type in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3goB5w1rfR_ia5aoND6HsA.png" /></figure><p>Then I continued to check the distinct outcomes of the arrests. There are <strong>15 </strong>different outcomes once an arrest is made in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gljgkeYSfhRXMiuRWO1Jg.png" /></figure><p><strong>Further analysis stage of the EDA</strong></p><p>I already have an idea of what the cleaned dataset looks like and what each column contains, therefore i can proceed with my analysis properly. We will be answering some questions with our dataset.</p><p><strong>Question 1: </strong>What is the count of arrests by each police unit?</p><p>The query below was used to get the police unit with the most arrests. The <strong>Metropolitan Police Service</strong> had the majority of arrests, followed closely by <strong>West Midlands Police</strong> and <strong>West Yorkshire Police</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eu6_Syl3_1FLrhwRLTWxSQ.png" /></figure><p><strong>Question 2: </strong>What crime type has the highest number of occurrences?</p><p>Violence and sexual offences have the highest incidence of arrests, with a total of <strong>1,242,243,</strong> followed by public order, criminal damage, and arson.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q8AwfBd5WeEsDA1kOTX5IA.png" /></figure><p><strong>Question 3: </strong>What month has the highest number of arrests?</p><p>The query shows that <strong>July</strong>, <strong>August</strong>, and <strong>October </strong>have the highest number of arrests, while <strong>December </strong>has the least.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SLtKGpoC73BPpbJoA718Wg.png" /></figure><p><strong>Question 4: </strong>What is the percentage of the top 10 police units that made the most arrests?</p><p>The result of the query shows The <strong>Metropolitan Police</strong> had <strong>16.31%</strong> of arrests, while <strong>West Midlands Police</strong> and <strong>West Yorkshire Police</strong> had <strong>7.29%</strong> and <strong>6.27%</strong>, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XKBwNsNtGQ65cmTvZM2Kaw.png" /></figure><p><strong>Question 5: </strong>What is the percentage of crime type prevalence?</p><p>The result of the query shows the percentage of the distribution of crime types in our data, with <strong>violence and sexual offences</strong> accounting for 41.41%, while <strong>public order</strong> and <strong>other theft</strong> were at 10.53% and 9.45%, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BskCVhGozzyhKdoC86yt3g.png" /></figure><p><strong>Question 6: </strong>What is the outcome of the crime incidence since July was the month with the most arrests, as reported by the Metropolitan Police Service, and Violence and sexual offences were the top crimes?</p><p><strong>14,651</strong> case status updates are unavailable, with<strong> 5439</strong> investigations completed without a suspect identified, while <strong>398</strong> are awaiting court outcomes, with <strong>86</strong> offenders given a caution and <strong>4 </strong>given a penalty notice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SwPsSKfTI0es2HkT7UXnbQ.png" /></figure><p>There are lots of insights that can be gotten from this huge dataset using basic SQL queries. I will present my analysis in <strong>visualization </strong>using Tableau in my next post.</p><p>Your feedback and comments are highly welcomed.</p><p><strong>Thank you!!!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f392e191b71" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>