<?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 Afan Annur Ayubi on Medium]]></title>
        <description><![CDATA[Stories by Afan Annur Ayubi on Medium]]></description>
        <link>https://medium.com/@afanayubi?source=rss-2222ca51ccd5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3In9C5cDj5WSNfJHF7uj4Q.jpeg</url>
            <title>Stories by Afan Annur Ayubi on Medium</title>
            <link>https://medium.com/@afanayubi?source=rss-2222ca51ccd5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 23:24:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@afanayubi/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[It was worth it.]]></title>
            <link>https://medium.com/@afanayubi/it-was-worth-it-d1af17819dbb?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1af17819dbb</guid>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Mon, 18 May 2026 15:22:18 GMT</pubDate>
            <atom:updated>2026-05-18T15:22:18.926Z</atom:updated>
            <content:encoded><![CDATA[<p>There are days in my life when the sky feels just too black,<br> and the night feels just too cold,<br> when numbness feels far too heavy to walk through.</p><p>So, I decided to crawl.<br> I decided to let the light hug me.<br> I thank myself for not stopping,<br> for choosing to stay,<br> even when I did not know where life was taking me.</p><p>And today, I know — <br> how delightful an iced coffee I had never known before could feel,<br> how happy I feel placing another 1 lb with every session,<br> how beautiful it feels to return to algebra, functions,<br> and even electrical things I once tried to put away,<br> how incredible life can be,<br> how peaceful forgiveness feels,<br> how mesmerizing it is when a second chance comes,<br> without me realizing how far I have come until today.</p><p>Not so many things have changed,<br> but who I am inside has changed a lot,<br> just because I kept trying to keep everything going.</p><p>It was worth it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1af17819dbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cultivating Dreams and Embracing Challenges: My Remarkable Journey as an Educator in Indonesian…]]></title>
            <link>https://medium.com/@afanayubi/cultivating-dreams-and-embracing-challenges-my-remarkable-journey-as-an-educator-in-indonesian-9058c9ae8dff?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9058c9ae8dff</guid>
            <category><![CDATA[educators]]></category>
            <category><![CDATA[journey]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Wed, 13 Nov 2024 10:34:53 GMT</pubDate>
            <atom:updated>2024-11-13T10:34:53.369Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cultivating Dreams and Embracing Challenges: My Remarkable Journey as an Educator in Indonesian Vocational High Schools</h3><p><strong>Engineer to Dreamer: My Leap of Faith</strong></p><p>Before I began my adventure as a teacher in an Indonesian vocational high school, my life was quite different. I was a mechanical engineer, dedicated to my work at a shoe factory in Sidoarjo. The job paid well, my coworkers were supportive, and I had a great work-life balance. To put it simply, it seemed like the perfect job, and I should have been content.</p><p>But deep down, I couldn’t shake the feeling that something essential was missing. I didn’t feel confident or passionate about my career, even though I was good at it. I had this burning desire to be part of something more significant, to have friends who shared my dreams, and to work with a team that believed in making a positive impact on society, even through small actions.</p><p>This inner struggle weighed on me, and I knew I had to make a tough choice. I had to leave behind the security and comfort of my stable job to pursue my true dreams. So, after saving up and doing some soul-searching, I gathered the courage to resign from my engineering job. I was ready to embrace the unknown and follow the path where my heart and dreams led me. It was a leap of faith, but I knew it was the right one.</p><p><strong>Diverse Paths and Unexpected Turns</strong></p><p>As I continued my journey of self-discovery, I found myself exploring various facets of the tech world. I tried my hand at digital marketing, tinkered with UI/UX design using Figma, ventured into the intriguing realm of product management, and even dipped my toes into the vast oceans of data analytics and data science. It was like a whirlwind of learning, and though I couldn’t claim mastery of every topic, I felt an immense sense of pride in how far I had come. I was on a quest for knowledge, and that, in itself, felt like a remarkable achievement.</p><p>But as time went on, I couldn’t help but feel that I was becoming a bit of a “jack of all trades, master of none.” It was as if I was skimming the surface of various fields but never truly diving deep into any one of them. Challenges arose, acting like imposing boulders obstructing my path and making it tough to showcase my skills effectively. My portfolio featured just a single project in product management and another in data analysis. The journey was no cakewalk, but I took solace in the fact that I was steadily progressing.</p><p>Amid this whirlwind of change, one unexpected blossom was my improvement in English proficiency. With each lesson, tutorial, and conversation, my grasp of the language grew stronger. While my communication still had its quirks, I felt increasingly at ease expressing myself in English. It was a skill that would prove invaluable in the adventures yet to come.</p><p>But then, my chosen path hit a roadblock. After two years of relentless pursuit, my parents grew increasingly worried about my unconventional career choices. They feared that I wouldn’t achieve anything substantial and believed that my age had closed the door on fresh starts. Their stress became my own, a heavy burden that weighed me down. It was a challenging time, with my mother’s silence echoing loudly as a sign of disapproval, and I grew weary from the constant tension.</p><p>I despised conflict and the feeling of being at odds with those I loved. It seemed as though I had become the antagonist, the one in the wrong. The pressure kept mounting, and it felt like an unending battle. On one front, I continued my job search, hoping to find a role that resonated with my newfound skills and passions. On the other front, my parents’ wishes cast a long shadow over my aspirations.</p><p>Ultimately, I chose to take a step back and try to understand things from my parents’ perspective. I recognized their concern, even when it felt suffocating. In a spirit of compromise, I decided to apply for a teaching position at one of the vocational schools in my hometown. It felt like a concession, a detour from the path I had envisioned for myself. Yet, I was willing to explore this avenue, if only to mend the rift that had formed between me and my parents.</p><p>I can still picture myself, super enthusiastic, trying to explain how lighting can change the mood when I did my teaching test. I asked people to imagine the difference between a Blackpink concert and a regular public space. I even did a little Blackpink impression using that signature tone. It was a time when I was comfortable with myself, so different from how I am now or how I used to be. Long story short, it’s already been a year of being a teacher in a vocational high school. There are ups and downs, fun and crying, tears and happy moments with the students and the system.</p><p>I was completely immersed in this feeling of making a difference in my students’ lives. I felt honored to help them discover themselves. Every day, I found immense joy in sharing my knowledge and listening to their thoughts and feelings. It wasn’t just about the subject matter; it was about connecting with them on a deeper level, celebrating their achievements, no matter how small. Of course, there were challenging times when they felt discouraged or misunderstood. But being a part of their journey, helping them navigate these obstacles, was truly fulfilling. It might sound cliché, but it’s the truth.</p><p>Being a teacher is a huge responsibility, and I take it seriously. I want to be more than just an instructor; I want to be an educator, someone who inspires a lifelong love of learning. I hope to show my students that the world is full of possibilities and that they have the potential to achieve great things. I encourage them to be brave, to pursue their dreams, and to understand that every small step brings them closer to their goals.</p><p>In the future, I hope to find a career that combines education with a well-paying field. I’m still figuring out my path, but I’m optimistic that there are no limits to what I can achieve. It might take time, but I believe that the journey will be worthwhile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9058c9ae8dff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Change Column Name in BigQuery]]></title>
            <link>https://medium.com/@afanayubi/overcoming-bigquery-sandbox-limitations-a-practical-guide-36150ed9bee3?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/36150ed9bee3</guid>
            <category><![CDATA[data-cleaning]]></category>
            <category><![CDATA[query]]></category>
            <category><![CDATA[data-preparation]]></category>
            <category><![CDATA[big-data-analytics]]></category>
            <category><![CDATA[bigquery]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Thu, 13 Jul 2023 06:13:30 GMT</pubDate>
            <atom:updated>2024-01-15T03:42:27.158Z</atom:updated>
            <content:encoded><![CDATA[<p>In the realm of Big Data and Analytics, Google’s BigQuery often stands out as a powerful tool that enables super-fast SQL queries against append-mostly tables using the processing power of Google’s infrastructure.</p><p>But what if you’re just starting out or testing some proof-of-concept ideas and want to limit your costs? That’s where BigQuery’s Sandbox comes in. The Sandbox provides free access to the capabilities of BigQuery with some limitations, which can sometimes make data manipulation a bit tricky.</p><p>One such limitation I encountered recently was while working with a table where the column names were unidentified, making it impossible to join with other tables. I wanted to rename the columns, but in Sandbox mode, we can’t directly make a table or execute data manipulation statements like INSERT, DELETE, or UPDATE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzoZ_yIXEhnvOLAjU4Ow1Q.png" /><figcaption>Figure 1</figcaption></figure><p>Figure 1 is the problem that I faced. The name in row number one should be the name of the column. To solve this, I came up with a workaround that I think can help others facing a similar situation. It can be used to change the name of the column using a simple query like this. and the result is in Figure 2.</p><pre>SELECT string_field_0 as pizza_type_id, <br>  string_field_1 as name, <br>  string_field_2 as category,<br>  string_field_3 as ingredients<br>FROM `myproject23-374506.PizzaDataset.pizza_types`</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hd_PtdmVbYUyMqYqkibQtA.png" /><figcaption>Figure 2</figcaption></figure><p>There is still a problem with the result. The row number one and the name of the column are still the same. Because the sandbox version of BigQuery didn’t permit to delete it directly. I use this query to solve the problem.</p><pre>SELECT<br>  string_field_0 as pizza_type_id, <br>  string_field_1 as name, <br>  string_field_2 as category,<br>  string_field_3 as ingredients<br>FROM (<br>  SELECT * <br>  FROM (<br>    SELECT *, ROW_NUMBER() OVER() as row_num<br>    FROM `PizzaDataset.pizza_types`<br>  ) <br>  WHERE row_num &gt;= 2 AND row_num &lt;= 33)</pre><p>In the table, there are a total of 33 rows. To solve this problem, we need to select rows 2 to 33. This can be done by first choosing the range of row numbers from 2 to 33. Once we have selected these rows, we can proceed to use the data within them for a specific statement. Finally, we have the option to rename a column using the “as” keyword. The result of this query is in Figure 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zUq3nk2rIk8O-QFTIdjJWQ.png" /><figcaption>Figure 3. Result After Editing</figcaption></figure><p>In Figure 3, the visual representation illustrates that the first row of data already corresponds to the column names. This crucial observation enables us to proceed with utilizing the dataset for the subsequent stage of analysis. This particular analysis step, which we have already completed, forms an integral part of the data preparation and cleansing process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36150ed9bee3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Case Study of Cyclistic Project using Python — Discover the Power of Data Analysis and…]]></title>
            <link>https://medium.com/@afanayubi/a-case-study-of-cyclistic-project-using-python-discover-the-power-of-data-analysis-and-bbbc877b7048?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbbc877b7048</guid>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[google-data-analytics]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 08:43:29 GMT</pubDate>
            <atom:updated>2023-04-26T08:43:29.720Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Case Study of Cyclistic Project using Python — Discover the Power of Data Analysis and Visualization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*17r72xlXRzYaGOAjqh0FCg.jpeg" /><figcaption>Pict illustration, source: <a href="https://www.freepik.com/free-photo/parked-city-bike-side-road_5180546.htm#page=3&amp;query=bike%20share&amp;position=22&amp;from_view=search&amp;track=robertav1_2_sidr">freepik</a></figcaption></figure><h3><strong>Scenario</strong></h3><p>As a junior data analyst at Cyclistic, a bike-sharing company in Chicago, you are part of a marketing team aiming to boost the number of annual memberships. To achieve this, your team is investigating <strong>the differences in how casual riders and annual members use Cyclistic bikes</strong>. Your goal is to gather insights and design a new marketing strategy <strong>to convert casual riders into annual members</strong>. To convince the Cyclistic executives to approve your recommendations, you need to provide solid data insights and professional visualizations that support your proposal.</p><h3>Company Profile</h3><p>Cyclistic is a bike-sharing program in Chicago that began in 2016 with just a few bikes, but now boasts a fleet of 5,824 bikes located across 692 stations throughout the city. Cyclistic’s marketing strategy in the past focused on building general awareness and appealing to broad consumer segments. Their pricing plans offer flexibility with single-ride passes, full-day passes, and annual memberships. Casual riders are customers who purchase single-ride or full-day passes, while annual memberships are reserved for Cyclistic members. The company’s finance analysts have concluded that <strong>annual members are much more profitable than casual riders.</strong> The director of marketing, Moreno, believes that the key to future growth is to maximize the number of annual members rather than target new customers. <strong>The goal is to convert casual riders into members by understanding how they differ and why casual riders would buy a membership.</strong> Moreno and her team plan to analyze Cyclistic’s historical bike trip data to identify trends that can inform their marketing tactics.</p><blockquote><strong>The table of content.</strong></blockquote><blockquote>Step 1: Ask</blockquote><blockquote>Step 2: Prepare</blockquote><blockquote>Step 3: Process</blockquote><blockquote>Step 4: Analysis and Visualization</blockquote><blockquote>Step 5: Insight and Recommendations</blockquote><h3><strong>Step 1: Ask</strong></h3><p>During the Ask phase, it’s important to consider two key questions:</p><ol><li>What is the problem that needs to be solved, and how can your insights drive business decisions? In the case of Cyclistic, the problem is how to convert casual riders to annual members, as financial analysts have determined that annual members are more profitable.</li><li>The director of marketing, Moreno, believes that converting casual riders to members is the best way to increase revenue. To accomplish this, analyzing the historical data of annual members and casual riders can help identify patterns that inform the best marketing strategy for converting casual riders to annual members.</li></ol><p>These are the question that we use to answer business tasks, this question that we will use to find the answer from Analyze phase.</p><ol><li>What is the current ratio of casual riders to annual members?</li><li>How do the usage patterns of casual riders compare to annual members?</li><li>What are the peak usage times for both casual riders and annual members?</li><li>What are the most popular pick-up and drop-off locations for both casual riders and annual members?</li><li>Are there any notable trends or patterns in the data that could suggest opportunities for converting casual riders into annual members?</li><li>Are there any particular days of the week or months of the year where casual ridership is particularly high or low?</li><li>Are there any geographic areas where Cyclistic should focus its marketing efforts to increase annual memberships?</li></ol><h3><strong>Step 2: Prepare</strong></h3><p>The second step of the analysis is to prepare. I download Cyclistic’s historical trip data from <a href="https://divvy-tripdata.s3.amazonaws.com/index.html">here</a>. (Note: The datasets have a different name because Cyclistic is a fictional company. For the purposes of this case study, the datasets are appropriate and have been made available by Motivate International Inc. under this <a href="https://ride.divvybikes.com/data-license-agreement">license</a>.) This is public data that can use to explore how different customer types are using Cyclistic bikes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EWFZdwRIcyZDYKVaRkcUJw.png" /><figcaption>Figure 1. Data Organizing</figcaption></figure><p>There are some questions that will help with finishing this phase. Let’s just go dive into it.</p><ol><li>Where is your data located? The data is located in the link above and is already under a license that can use.</li><li>How has the data been structured? As indicated in Figure 1 from the aforementioned link, there are three data types available. For the purpose of this analysis, I am utilizing the red data type. Once the data has been downloaded, I extract it and rename it as “dfyear_month”, with “df” representing “data frame”. Specifically, I am using data from January to December 2022.</li><li>Are there issues with bias or credibility in this data? Does your data ROCCCs?</li></ol><ul><li>Reliable: The data set was trustworthy and accurate with minimal error after I check it using SQL and Python.</li><li>Original: Of course the data was Original. the originality of the data could be checked in the license link above.</li><li>Comprehensive: Yes the data is comprehensive. It was relatable to the case that we want to use.</li><li>Current: Yes. the data is still up-to-date, specifically from the year 2022</li><li>Cited: Yes the data is cited. from the year 2022, all the data is in the link above. but we need to merge all the data together to make it easier.</li></ul><p>4. How are you addressing licensing, privacy, security, and accessibility? You can verify the licensing information from the link provided. As for privacy and security, they are maintained as the data does not contain any personally identifiable information such as credit card numbers or names that need to be protected.</p><p>5. How did you verify the data’s integrity? The data source is legitimate as it is obtained from the bike-share program in Chicago and is licensed. The City of Chicago has complete ownership of the Data, as indicated in the licensing information.</p><p>6. How does the data help you answer your question? The data contains a total of 13 columns, which include ride_id, rideable_type, started_at, ended_at, start_station_name, start_station_id, end_station_name, end_station_id, start_lat, start_lng, end_lat, end_lng, and member_casual. These columns provide crucial information that can be used to address all the questions identified in the asking phase.</p><p>7. Are there any problems with the data? Of course, there are missing values and outliers after I check in the process step, but I will try to handle it.</p><h3><strong>Step 3: Process</strong></h3><p>In the fourth step of the analysis, which is the process, I will utilize Python to conduct data cleaning and examine the information provided by the activity of both the member and casual bikers. As I am using Jupyter Notebook for this task, Here is the step-by-step that I use for the process.</p><p>First, Import the library that will be needed for the process and analysis.</p><pre># acquire library<br>import pandas as pd<br>import datetime<br>import numpy as np<br>import matplotlib.pyplot as plt<br>import seaborn as sns</pre><p>Afterward, use pd.read_csv to read the CSV file from a local directory and create a data frame. The following code is an example of how to accomplish this task.</p><pre>df22_01 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_01.csv&#39;)<br>df22_02 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_02.csv&#39;)<br>df22_03 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_03.csv&#39;)<br>df22_04 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_04.csv&#39;)<br>df22_05 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_05.csv&#39;)<br>df22_06 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_06.csv&#39;)<br>df22_07 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_07.csv&#39;)<br>df22_08 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_08.csv&#39;)<br>df22_09 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_09.csv&#39;)<br>df22_10 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_10.csv&#39;)<br>df22_11 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_11.csv&#39;)<br>df22_12 = pd.read_csv(&#39;/Users/afanayubi/DATA/Data Analyst/CaseStudy-1/divvy-tripdata-csv/df22_12.csv&#39;)</pre><p>Subsequently, use pd.concat() to combine all of the data and assign it the name df2022. Here is the code that I used to merge the data frame into one data frame as df20022.</p><pre># merge data frame into one data frame<br># use the pd.concat() function from the pandas library to merge columns with the same data type into a single column.<br>df2022 = pd.concat([df22_01, df22_02, df22_03, df22_04, df22_05, df22_06, df22_07, df22_08, df22_09, df22_10, df22_11, df22_12], axis = 0)<br>df2022 # use to call the data</pre><p>Figure 2. shows the result that all the data already merge and ready for the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IkYxMJvVq--bLmQU25T4A.png" /><figcaption>Figure 2. All the data after combine</figcaption></figure><p>Next, I want to check the info from all the columns. I use .info() and the result is shown in Figure 3.</p><pre># check the data frame<br>df2022.info()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*GT4FU31ZhLnd5aoWMtLnXQ.png" /><figcaption>Figure 3. df2022.info()</figcaption></figure><p>Figure 3 displays information about the data frame which contains 5.667.717 rows and 13 columns. Each column’s data type is shown in the figure. The data type for the started_at and ended_at columns are currently classified as objects, but they should be classified as dates and times instead. To correct this, I will modify their data types to date using the following code.</p><pre># convert started_at and ended_at columns as datetime<br>df2022[&#39;started_at&#39;] = pd.to_datetime(df2022[&#39;started_at&#39;])<br>df2022[&#39;ended_at&#39;] = pd.to_datetime(df2022[&#39;ended_at&#39;])</pre><p>After that, I want to check missing value or null from the data using .isnull() and count how much null from the data with .sum(). The result is in Figure 4.</p><pre># Checking NaN value from data frame<br>nan_count = df2022.isnull().sum()<br>print(nan_count)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*-WgRbXteiAxc8G5qpu_J3A.png" /><figcaption>Figure 4. Checking null value</figcaption></figure><p>Based on Figure 4, some columns such as start_station_name, start_station_id, end_station_name, end_lat, and end_lng contain null values. To handle this, I aim to fill the null values in the start_station_name, start_station_id, end_station_name, and end_station_id columns with their respective name based on their latitude and longitude. To achieve this, I will use a code for each column.</p><pre># Replace the missing values in the start_station_name column by using start_lat and start_lng column to determine the location.<br>def fill_col1(row):<br>    if pd.isnull(row[&#39;start_station_name&#39;]):<br>        return row[&#39;start_lat&#39;] + row[&#39;start_lng&#39;]<br>    else:<br>        return row[&#39;start_station_name&#39;]<br><br># apply the function to fill NaN values in col1<br>df2022[&#39;start_station_name&#39;] = df2022.apply(fill_col1, axis=1)</pre><pre># Replace the missing values in the start_station_name column by using start_lat and start_lng column to determine the location.<br>def fill_col1(row):<br>    if pd.isnull(row[&#39;start_station_id&#39;]):<br>        return row[&#39;start_lat&#39;] + row[&#39;start_lng&#39;]<br>    else:<br>        return row[&#39;start_station_id&#39;]<br><br># apply the function to fill NaN values in col1<br>df2022[&#39;start_station_id&#39;] = df2022.apply(fill_col1, axis=1)</pre><pre># Replace the missing values in the end_station_name column by using end_lat and end_lng column to determine the location.<br>def fill_col1(row):<br>    if pd.isnull(row[&#39;end_station_name&#39;]):<br>        return row[&#39;end_lat&#39;] + row[&#39;end_lng&#39;]<br>    else:<br>        return row[&#39;end_station_name&#39;]<br><br># apply the function to fill NaN values in col1<br>df2022[&#39;end_station_name&#39;] = df2022.apply(fill_col1, axis=1)</pre><pre># Replace the missing values in the end_station_name column by using end_lat and end_lng column to determine the location.<br>def fill_col1(row):<br>    if pd.isnull(row[&#39;end_station_id&#39;]):<br>        return row[&#39;end_lat&#39;] + row[&#39;end_lng&#39;]<br>    else:<br>        return row[&#39;end_station_id&#39;]<br><br># apply the function to fill NaN values in col1<br>df2022[&#39;end_station_id&#39;] = df2022.apply(fill_col1, axis=1)</pre><p>and I use the median from end_lat and end_lng to fill the null value and “ not identified” in columns end_station_name and end_station_id which didn’t have any value with this code.</p><pre># Fill NaN values with the median value of the respective column for end_lat and end_lng<br>df2022[&#39;end_lat&#39;].fillna(df2022[&#39;end_lat&#39;].median(), inplace=True)<br>df2022[&#39;end_lng&#39;].fillna(df2022[&#39;end_lng&#39;].median(), inplace=True)</pre><pre># Fill NaN values with the median value of the respective column for end_lat and end_lng<br>df2022[&#39;end_station_name&#39;].fillna(&quot;not identified&quot;, inplace=True)<br>df2022[&#39;end_station_id&#39;].fillna(&quot;not identified&quot;, inplace=True)</pre><p>Here is the outcome displayed in Figure 5 after handling the null values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*VNxcspywprXQ1GBtIupsYg.png" /><figcaption>Figure 5. Checking again null value</figcaption></figure><p>After all null value fill in, we go to the next step. I want to calculate the distance from start to end. I use the haversine repository in the code below to calculate it.</p><pre>import math<br>def haversine(lon1, lat1, lon2, lat2):<br>    &quot;&quot;&quot;<br>    Calculate the great circle distance between two points <br>    on the earth (specified in decimal degrees)<br>    &quot;&quot;&quot;<br>    # convert decimal degrees to radians <br>    lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2])<br><br>    # haversine formula <br>    dlon = lon2 - lon1 <br>    dlat = lat2 - lat1 <br>    a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2<br>    c = 2 * math.asin(math.sqrt(a)) <br>    r = 6371 # Radius of earth in kilometer. Use 3956 for miles<br>    return c * r<br><br># Example usage<br>lat1 = 40.748817<br>lon1 = -73.985428<br>lat2 = 37.774929<br>lon2 = -122.419416<br><br>distance = round(haversine(lon1, lat1, lon2, lat2), 2)<br>print(distance)</pre><p>From the haversine syntax above just fill the column from the start_lng, start_lat, end_lng, and end_lat the code like the code below.</p><pre># calculate the distance from start to end<br>df2022[&#39;distance&#39;] = df2022.apply(lambda row: haversine(row[&#39;start_lng&#39;], row[&#39;start_lat&#39;], row[&#39;end_lng&#39;], row[&#39;end_lat&#39;]), axis=1)</pre><p>After adding the column name as distance, I want to check the result, if there are any outliers or not in there with the boxplot. And the result is in Figure 6.</p><pre># Select a column to plot<br>data_distance = &quot;distance&quot;<br>data = df2022[data_distance]<br><br># Create a boxplot<br>plt.boxplot(data)<br><br># Add title and labels<br>plt.title(&quot;Boxplot of &quot; + data_distance)<br>plt.ylabel(&quot;Value&quot;)<br><br># Show the plot<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*XKyPLDYt5vgSvEUMQ9mC4Q.png" /><figcaption>Figure 6. Checking outliers from column distance</figcaption></figure><p>Figure 6. shows there are outliers there. the orange line is the median and most of the data is there. and then, it is really impossible from the distance has almost 10.000km. I use the Interquartile Range which is a measure of statistical dispersion used to identify the spread of a data set. It is the range between the first quartile (25th percentile) and the third quartile (75th percentile) of a data set. It is a measure of the middle 50% of the data and is used to identify potential outliers in the data. After the outliers find, I remove them by negation symbol and named them df2022_1 the result is in Figure 7. The code for the outliers is below.</p><pre>pct_95 = np.percentile(df2022[&#39;distance&#39;], 95)<br>iqr = np.percentile(df2022[&#39;distance&#39;], 75) - np.percentile(df2022[&#39;distance&#39;], 25)<br>upper_bound = np.percentile(df2022[&#39;distance&#39;], 75) + 1.5 * iqr<br>lower_bound = np.percentile(df2022[&#39;distance&#39;], 25) - 1.5 * iqr<br><br>outliers = df2022[&#39;distance&#39;][(df2022[&#39;distance&#39;] &gt; upper_bound) | (df2022[&#39;distance&#39;] &lt; lower_bound)]<br>df2022_1 = df2022[~((df2022[&#39;distance&#39;] &gt; upper_bound) | (df2022[&#39;distance&#39;] &lt; lower_bound))] #filtered the outliers in column distance</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*uJZRGWAsFPhnrZJCupghnw.png" /><figcaption>Figure 7. Boxplot Distance after removing the outliers</figcaption></figure><p>Based on Figure 7, we can observe that the median distance of the bike rides is between 1 and 2 kilometers. The figure provides a visual representation of the data distribution.</p><p>After eliminating the outliers in the distance column, my next step is to create a new column named “time_diff”, which will display the length of time the riders spent using the bicycle. Here is the code I used for this task.</p><pre># Looking for time differences between start and end<br>df2022_1[&#39;time_diff&#39;] = (df2022_1[&#39;ended_at&#39;] - df2022_1[&#39;started_at&#39;]).astype(&#39;timedelta64[m]&#39;)</pre><p>To ensure clearer data, I will also check for outliers in the time_diff column using the same method as before. I will show the boxplot before and remove any outliers. Then, we can see the resulting data. Here is the code that I use.</p><pre># Select a column to plot<br>data_difference = &quot;time_diff&quot;<br>data = df2022_1[data_difference]<br><br># Create a boxplot<br>plt.boxplot(data)<br><br># Add title and labels<br>plt.title(&quot;Boxplot of &quot; + &quot;time_diff&quot;)<br>plt.ylabel(&quot;Value&quot;)<br><br># Show the plot<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*kc7zZ2Ve1erO5lMAuM6vhA.png" /><figcaption>Figure 8. Boxplot of time_diff column with outliers</figcaption></figure><p>Figure 8 displays numerous outliers ranging from negative 10,000 to over 30,000 minutes, which does not make sense. It is odd to have a negative value as the formula used is “ended_at minus started_at.” The median is close to zero, and the values are in minutes. If we compare it with the distance result from before, we can see that the maximum distance covered was 5 kilometers, yet someone used the bike for over 30,000 minutes. Hence, we need to remove the outliers and analyze the results again. Figure 9. shows the time_diff column without outliers. the median is approximately 10 minutes.</p><pre>#filtered the outliers in column time_diff<br>pct_95 = np.percentile(df2022_1[&#39;time_diff&#39;], 95)<br>iqr = np.percentile(df2022_1[&#39;time_diff&#39;], 75) - np.percentile(df2022_1[&#39;time_diff&#39;], 25)<br>upper_bound = np.percentile(df2022_1[&#39;time_diff&#39;], 75) + 1.5 * iqr<br>lower_bound = np.percentile(df2022_1[&#39;time_diff&#39;], 25) - 1.5 * iqr<br><br>outliers = df2022_1[&#39;time_diff&#39;][(df2022_1[&#39;time_diff&#39;] &gt; upper_bound) | (df2022_1[&#39;time_diff&#39;] &lt; lower_bound)]<br>df2022_2 = df2022_1[~((df2022_1[&#39;time_diff&#39;] &gt; upper_bound) | (df2022_1[&#39;time_diff&#39;] &lt; lower_bound))] </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*X3VwfMfGYREt_Vm19ZJDag.png" /><figcaption>Figure 9. Boxplot of time_diff after removing the outliers</figcaption></figure><p>Next, I aim to eliminate any duplicate entries in the data frame by using the ride_id column. Since the ride_id column has unique values compared to the other columns, I chose to use this column for removing duplicates. Below is the syntax that I employed for this purpose. Once all the outliers and duplicates have been removed, the data set is left with 4,839,699 rows out of the initial 5,667,717 rows.</p><pre># remove duplicates based on the &#39;ride_id&#39; column<br>df2022_2.drop_duplicates(subset=&#39;ride_id&#39;, inplace=True)</pre><p>I intend to add additional columns to split the date and time from the start column into month, day, and hour. The code below is what I use for this purpose.</p><pre># extract datetime to month<br>df2022_2[&#39;started_month&#39;] = df2022_2[&#39;started_at&#39;].dt.strftime(&quot;%m&quot;)<br><br># extract datetime to day in a week<br>df2022_2[&#39;started_day&#39;] = df2022_2[&#39;started_at&#39;].dt.strftime(&quot;%A&quot;)<br><br># extract datetime to hour<br>df2022_2[&#39;started_hour&#39;] = df2022_2[&#39;started_at&#39;].dt.hour</pre><p>Now we have a clean and organized data frame to continue our journey into the exciting world of data analysis! These steps were crucial in ensuring that our data is reliable and trustworthy, so we can now focus on analyzing the data and extracting insights that can help us answer our business questions. With the power of Python and data visualization tools, we can uncover hidden patterns and trends that could lead to groundbreaking discoveries. So let’s dive in and unleash the power of data analysis!</p><h3><strong>Step 4: Analysis and Visualization</strong></h3><p>We start step 4 for the analysis by determine <strong>the ratio of members and casual</strong> riders, I group the data by the “member_casual” column and count the number of members and casual riders. The following is the code I utilized.</p><pre>current_ratio = df2022_2.groupby(&#39;member_casual&#39;)[&#39;member_casual&#39;].count()<br>print(current_ratio)</pre><p>Figure 10. showing the result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kBNyS_WNkRS3Q_YSzj1yHQ.png" /><figcaption>Figure 10. The ratio result</figcaption></figure><p>To enhance clarity and facilitate readability, I utilized a pie chart to visualize the ratio, using the following code. The resulting output is displayed in Figure 11.</p><pre># Group data by &#39;member_casual&#39; and count the number of rows<br>grouped_data = df2022_2.groupby(&#39;member_casual&#39;).size()<br><br># Create a list of colors for the pie chart<br>colors = [&#39;navy&#39;, &#39;orange&#39;]<br><br># Create the pie chart<br>plt.pie(grouped_data, labels=grouped_data.index, colors=colors, autopct=&#39;%1.1f%%&#39;)<br><br># Add a title to the chart<br>plt.title(&#39;Number of Rides by Member/Casual Riders&#39;)<br><br># Display the chart<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*jCz_Bf8SncMKLQwIR7yA2A.png" /><figcaption>Figure 11. Pie chart ratio</figcaption></figure><p>Based on the ratio of members and casual riders, we can observe that there is a 38.2% chance of converting from a member to a casual rider.</p><p>Next, I performed statistical analysis (mean, median, and mode) on the “time_diff” and “distance” columns separately for both members and casual riders. The code I used and the resulting output in Figure 12 are provided below.</p><p><strong>Statistical Analysis “time_diff”</strong></p><pre># Mean by column time_diff<br>mean_time = df2022_2.groupby(&#39;member_casual&#39;)[&#39;time_diff&#39;].mean()<br>print(mean_time)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvMWO66Jhx9d9JhcimFSXg.png" /><figcaption>Figure 12. Mean result for time_diff</figcaption></figure><pre># Median by column time_diff<br>median_time = df2022_2.groupby(&#39;member_casual&#39;)[&#39;time_diff&#39;].median()<br>print(median_time)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PT3WBFf1NIyqBsU7NZA-Q.png" /><figcaption>Figure 13. Median result for time_diff</figcaption></figure><pre># Mode by column time_diff<br>mode_time = df2022_2.groupby(&#39;member_casual&#39;)[&#39;time_diff&#39;].apply(lambda x: x.mode()).tolist()<br>print(mode_time)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhOglUw925--AX5tt2RwlA.png" /><figcaption>Figure 14. Mode result for time_diff</figcaption></figure><p><strong>Statistical Analysis “distance”</strong></p><pre># Mean by column distance<br>mean_distance = df2022_2.groupby(&#39;member_casual&#39;)[&#39;distance&#39;].mean()<br>print(mean_distance)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8hEK9cS0KJNl6HTNjONkQ.png" /><figcaption>Figure 15. Mean result for distance</figcaption></figure><pre># Median by column distance<br>median = df2022_2.groupby(&#39;member_casual&#39;)[&#39;distance&#39;].median()<br>print(median)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXEqOdIwo27UFA0Aovv9dw.png" /><figcaption>Figure 16. Median result for distance</figcaption></figure><pre># Mode by column distance<br>mode = df2022_2.groupby(&#39;member_casual&#39;)[&#39;distance&#39;].apply(lambda x: x.mode()).tolist()<br>print(mode)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eeNqTJrEtKasC8X16RX-zw.png" /><figcaption>Figure 17. Mode result for distance</figcaption></figure><p>Based on the provided data, we can make the following observations and analysis:</p><ol><li>On average, casual users spend more time on their bicycle rentals (mean: 11.73 minutes) compared to members (mean: 9.21 minutes). This could suggest that casual users enjoy their rides and are open to spending more time exploring or riding for leisure.</li><li>The median values show a similar trend, with casual users spending 10 minutes per ride, while members spend 8 minutes. This indicates that at least 50% of casual users are taking longer rides than 50% of the members.</li><li>The mode values indicate that the most common duration for casual users is 7 minutes, while for members it is 4 minutes. This shows that there is a significant portion of members who use the service for shorter rides.</li><li>Analyzing the distance data, we observe that casual users, on average, travel slightly longer distances (mean: 1.83 km) than members (mean: 1.76 km). The median distances follow a similar pattern, with casual users traveling 1.59 km and members traveling 1.40 km.</li><li>The mode values for both casual and member users are 0.0 km, which suggests that a significant portion of users, regardless of their user type, start and end their rides at the same location. This indicates that users might be using the bicycles for leisurely rides or exercise purposes, rather than strictly for transportation between different points.</li></ol><p>The subsequent analysis we aim to investigate involves identifying the most frequently used stations for starting and ending rides for both casual and member users. This information can be employed in marketing strategies to target advertisements and promotional campaigns based on geographical location. This is the code implemented to identify the top 5 most frequently used start and end station names for both casual and member riders. The resulting data reveals the five most popular stations for each category of users.</p><p><strong>Start Station Names</strong></p><pre># group by both &#39;start_station_name&#39; and &#39;member_casual&#39; columns and count the number of occurrences for &#39;member_casual&#39; riders only<br>count_station_member = df2022_2.loc[df2022_2[&#39;member_casual&#39;] == &#39;member&#39;].groupby([&#39;start_station_name&#39;])[&#39;member_casual&#39;].count().reset_index(name=&#39;count&#39;).sort_values(by=&#39;count&#39;, ascending=False)<br>print(count_station_member.head(n=5))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*1YPxIukCIX068jHC4MtawA.png" /><figcaption>Figure 18. Top 5 start station names for members</figcaption></figure><pre># group by both &#39;start_station_name&#39; and &#39;member_casual&#39; columns and count the number of occurrences for &#39;member_casual&#39; riders only<br>count_station_casual = df2022_2.loc[df2022_2[&#39;member_casual&#39;] == &#39;casual&#39;].groupby([&#39;start_station_name&#39;])[&#39;member_casual&#39;].count().reset_index(name=&#39;count&#39;).sort_values(by=&#39;count&#39;, ascending=False)<br>print(count_station_casual.head(n=5))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*Owr4VbROI1V72Bg3Iye3og.png" /><figcaption>Figure 19. Top 5 start station names for casual riders</figcaption></figure><p><strong>End Station Names</strong></p><pre># group by both &#39;start_station_name&#39; and &#39;member_casual&#39; columns and count the number of occurrences for &#39;member_casual&#39; riders only<br>count_station_member_end = df2022_2.loc[df2022_2[&#39;member_casual&#39;] == &#39;member&#39;].groupby([&#39;end_station_name&#39;])[&#39;member_casual&#39;].count().reset_index(name=&#39;count&#39;).sort_values(by=&#39;count&#39;, ascending=False)<br>print(count_station_member_end.head(n=5))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*DV651CHIuRrThPOjqnxniQ.png" /><figcaption>Figure 20. Top 5 end station names for members</figcaption></figure><pre># group by both &#39;start_station_name&#39; and &#39;member_casual&#39; columns and count the number of occurrences for &#39;member_casual&#39; riders only<br>count_station_member_end = df2022_2.loc[df2022_2[&#39;member_casual&#39;] == &#39;casual&#39;].groupby([&#39;end_station_name&#39;])[&#39;member_casual&#39;].count().reset_index(name=&#39;count&#39;).sort_values(by=&#39;count&#39;, ascending=False)<br>print(count_station_member_end.head(n=5))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*gTswzlDRtjs0SHZVaQw9aQ.png" /><figcaption>Figure 21. Top 5 end station names for casual riders</figcaption></figure><p>These data provide valuable insights into the usage patterns and behavior of both member and casual riders. For members, the most popular stations are located in and around the downtown area, suggesting that they primarily use the bike-sharing service for commuting or daily activities. In contrast, casual riders tend to favor stations near tourist attractions and recreational areas, indicating that they may be using the service for leisure or sightseeing purposes.</p><p>For the upcoming analysis, I am interested in understanding the riding patterns of members and casual riders across different days and months. I have written some code for this purpose and obtained the corresponding results and visualizations.</p><p><strong>Days</strong></p><pre># group by both &#39;member_casual&#39; and &#39;started_day&#39; columns and count the number of occurrences<br>count_day = df2022_2.groupby([&#39;started_day&#39;, &#39;member_casual&#39;])[&#39;member_casual&#39;].count().reset_index(name=&#39;count&#39;)<br>print(count_day)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*vxObErKGQSmX8n77JEjObw.png" /><figcaption>Figure 22. Days of the week calculation from members and casual riders</figcaption></figure><pre># create an ordered list of days of the week<br>days = [&#39;Monday&#39;, &#39;Tuesday&#39;, &#39;Wednesday&#39;, &#39;Thursday&#39;, &#39;Friday&#39;, &#39;Saturday&#39;, &#39;Sunday&#39;]<br><br># group by started_day and member_casual columns and sum the distance<br>grouped = df2022_2.groupby([&#39;started_day&#39;, &#39;member_casual&#39;])[&#39;distance&#39;].sum().reset_index()<br><br># pivot the table to create a separate column for member and casual distances<br>pivoted = grouped.pivot(index=&#39;started_day&#39;, columns=&#39;member_casual&#39;, values=&#39;distance&#39;)<br><br># reindex the pivoted table with the ordered list of days<br>pivoted = pivoted.reindex(days)<br><br># create bar chart<br>pivoted.plot(kind=&#39;bar&#39;)<br><br># add labels and title<br>plt.xlabel(&#39;Day of the Week&#39;)<br>plt.ylabel(&#39;Total Distance (Kilometer)&#39;)<br>plt.title(&#39;Total Distance Traveled by Rider Type and Day of the Week&#39;)<br><br># display chart<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*upM2s6b1lR7Uz-2EmD7hfw.png" /><figcaption>Figure 23. Bar chart for day of the week distribution</figcaption></figure><p>Casual riders show a clear preference for weekends, with the highest usage on Saturdays and Sundays. This suggests that casual riders are more likely to use the bike-sharing service for leisure activities or sightseeing during their free time on weekends. Usage is relatively consistent across weekdays, with a slight increase on Fridays.</p><p>Member riders, on the other hand, exhibit a different pattern. They use the service more heavily during weekdays, with the highest usage on Thursdays, followed by Wednesdays and Tuesdays. This indicates that member riders are likely using the bike-sharing service for commuting or daily activities during the workweek. Usage drops significantly on weekends, particularly on Sundays.</p><p>In summary, casual riders tend to use the bike-sharing service more frequently on weekends, while member riders show higher usage during weekdays. This insight can be used to tailor marketing campaigns, promotions, and services to better cater to the different usage patterns and preferences of casual and member riders.</p><p><strong>Months</strong></p><pre># count month<br>count_month = df2022_2.groupby([&#39;started_month&#39;, &#39;member_casual&#39;])[&#39;member_casual&#39;].count().reset_index(name=&#39;count&#39;)<br>print(count_month)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*ualxMuabG35PPzMMFJHvQQ.png" /><figcaption>Figure 24. Months calculation from members and casual riders</figcaption></figure><pre># create an ordered list of days of the week<br>month = [&#39;01&#39;, &#39;02&#39;, &#39;03&#39;, &#39;04&#39;, &#39;05&#39;, &#39;06&#39;, &#39;07&#39;, &#39;08&#39;, &#39;09&#39;, &#39;10&#39;, &#39;11&#39;, &#39;12&#39;]<br><br># group by started_day and member_casual columns and sum the distance<br>grouped = df2022_2.groupby([&#39;started_month&#39;, &#39;member_casual&#39;])[&#39;distance&#39;].sum().reset_index()<br><br># pivot the table to create a separate column for member and casual distances<br>pivoted = grouped.pivot(index=&#39;started_month&#39;, columns=&#39;member_casual&#39;, values=&#39;distance&#39;)<br><br># reindex the pivoted table with the ordered list of days<br>pivoted = pivoted.reindex(month)<br><br># create bar chart<br>pivoted.plot(kind=&#39;bar&#39;)<br><br># add labels and title<br>plt.xlabel(&#39;Month&#39;)<br>plt.ylabel(&#39;Total Distance (Kilometer)&#39;)<br>plt.title(&#39;Total Distance Traveled by Rider Type and Months of the Year&#39;)<br><br># display chart<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*d2P1kzXRUW3DxOCn4xTZ-Q.png" /><figcaption>Figure 25. Bar chart for Month distribution</figcaption></figure><p>Casual riders show a strong preference for warmer months, with the highest usage in July, August, and June. This suggests that casual riders are more likely to use the bike-sharing service when the weather is more favorable for outdoor activities. Usage decreases significantly during colder months, particularly in January and February.</p><p>Member riders also exhibit higher usage during warmer months, but they maintain a more consistent usage pattern throughout the year. This indicates that member riders are likely using the bike-sharing service for various purposes, including commuting, daily activities, and leisure, and are less affected by the change in seasons.</p><p>In summary, both casual and member riders tend to use the bike-sharing service more frequently during warmer months. However, casual riders are more sensitive to seasonal changes, while member riders exhibit a more consistent usage pattern throughout the year. This insight can be used to tailor marketing campaigns, promotions, and services to better cater to the different usage patterns and preferences of casual and member riders.</p><p>Next, I just make a pie chart to shows how the distribution from member and casual in weekdays and weekend. Here is the code that I use followed by the result.</p><pre># Filter data to include only weekends<br>weekday_data = df2022_2[df2022_2[&#39;started_day&#39;].isin([&#39;Monday&#39;, &#39;Tuesday&#39;, &#39;Wednesday&#39;, &#39;Thursday&#39;, &#39;Friday&#39;])]<br><br># Group data by &#39;member_casual&#39; and sum the &#39;distance&#39;<br>grouped_data = weekday_data.groupby(&#39;member_casual&#39;)[&#39;distance&#39;].sum()<br><br># Create a list of colors for the pie chart<br>colors = [&#39;cornflowerblue&#39;, &#39;pink&#39;]<br><br># Create the pie chart<br>plt.pie(grouped_data, labels=grouped_data.index, colors=colors, autopct=&#39;%1.1f%%&#39;)<br><br># Add a title to the chart<br>plt.title(&#39;Distance Traveled by Member/Casual Riders on Weekdays&#39;)<br><br># Display the chart<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*U71SdNZ4iqpIL-oRj_pYUA.png" /><figcaption>Figure 26.Pie chart for Members and Casual on the weekdays</figcaption></figure><pre># Filter data to include only weekends<br>weekend_data = df2022_2[df2022_2[&#39;started_day&#39;].isin([&#39;Saturday&#39;, &#39;Sunday&#39;])]<br><br># Group data by &#39;member_casual&#39; and sum the &#39;distance&#39;<br>grouped_data = weekend_data.groupby(&#39;member_casual&#39;)[&#39;distance&#39;].sum()<br><br># Create a list of colors for the pie chart<br>colors = [&#39;cornflowerblue&#39;, &#39;pink&#39;]<br><br># Create the pie chart<br>plt.pie(grouped_data, labels=grouped_data.index, colors=colors, autopct=&#39;%1.1f%%&#39;)<br><br># Add a title to the chart<br>plt.title(&#39;Distance Traveled by Member/Casual Riders on Weekends&#39;)<br><br># Display the chart<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*t3elw5nZGDDAVP_X__bh0A.png" /><figcaption>Figure 27. Pie chart for Members and Casual on the weekend</figcaption></figure><p>The data suggests that member riders make up a larger percentage of total rides during weekdays, while casual riders have a more significant presence on weekends. This difference in rider behavior could indicate that member riders are more likely to use the bike-sharing service for regular commuting and daily activities, which typically occur on weekdays.</p><p>On the other hand, casual riders seem to prefer using the service on weekends, potentially for leisure activities and exploring the city. The higher percentage of casual riders during weekends might be due to their more flexible schedules, while member riders may have a more consistent routine throughout the week.</p><p>In summary, member riders tend to dominate the bike-sharing service usage during weekdays, suggesting a higher reliance on the service for commuting and daily activities. Casual riders are more prominent during weekends, likely using the service for leisure and recreational purposes. Understanding these patterns can help inform marketing strategies, promotional campaigns, and service adjustments to better cater to the distinct needs and preferences of casual and member riders.</p><h3><strong>Step 5: Insight &amp; Recommendation</strong></h3><p>Here are the consolidated insights and recommendations to convert casual riders into members, based on the data analysis:</p><ol><li>Targeted Marketing on Weekends: Since casual riders use the service more on weekends, focus marketing efforts and promotions during weekends. Offer exclusive member benefits or discounts for rides taken on weekends to attract casual riders to become members.</li><li>Emphasize Cost Savings: Casual users tend to spend more time on their rides and travel slightly longer distances. Target these users with membership offers that emphasize the cost savings associated with longer ride times and distances to make membership more appealing.</li><li>Geographical Targeting: Utilize the data on the most popular starting and ending stations for casual riders to target specific locations with advertising and promotional campaigns. By focusing on these high-traffic areas, you can effectively reach casual riders and communicate the benefits of becoming a member.</li><li>Seasonal Promotions: Casual ridership increases during warmer months (May-September). Introduce seasonal promotions, such as discounted membership rates or added benefits during these months, to encourage casual riders to convert to membership.</li><li>Flexible Membership Plans: Offer flexible membership plans (such as weekly or monthly options) that cater to the specific needs and preferences of casual riders. This can help casual riders see the value in becoming members without feeling locked into a long-term commitment.</li><li>Promote Health and Fitness Benefits: Highlight the health and fitness benefits of cycling, and encourage casual riders to incorporate bike-sharing into their regular exercise routines by offering member-exclusive fitness challenges or rewards.</li><li>Special Events and Community Building: Develop and promote special events or group rides for casual users to build a sense of community and showcase the benefits of becoming a member. By creating a positive and inclusive atmosphere, casual users might be more likely to convert to members.</li><li>Personalized Recommendations: Offer personalized recommendations or route suggestions based on casual users’ ride history to demonstrate the added value that comes with membership and encourage them to join.</li><li>Testimonials and Success Stories: Share testimonials and success stories from casual riders who have become members and benefited from the membership. This will create a sense of relatability and trust, helping casual riders see the potential benefits of converting to membership.</li></ol><p>At last, I’ve completed my first case study analysis using Python, and the feeling of accomplishment is incredible. After finishing the Google Data Analytics course on Coursera in December 2022, I can now proudly share my work from this case study in April 2023. Although it took longer than expected, I believe I can improve and work more efficiently on future case studies. Sometimes, my overthinking and desire for perfection can hold me back, but I know this project isn’t flawless. If you’d like to discuss or share your thoughts, feel free to reach out to me through direct messages, comments, or connect with me on LinkedIn. Here’s the link to my profile: <a href="https://www.linkedin.com/in/afanannurayubi/">https://www.linkedin.com/in/afanannurayubi/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbbc877b7048" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get Focused and Relaxed: The Power of Reading to Reduce Stress and Improve Concentration]]></title>
            <link>https://medium.com/@afanayubi/get-focused-and-relaxed-the-power-of-reading-to-reduce-stress-and-improve-concentration-f4b8409a93af?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4b8409a93af</guid>
            <category><![CDATA[books]]></category>
            <category><![CDATA[stress-relief]]></category>
            <category><![CDATA[focus]]></category>
            <category><![CDATA[reading]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 09:26:09 GMT</pubDate>
            <atom:updated>2023-04-11T09:26:09.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsHJ5dmJemH6Vhs2rE87kQ.png" /><figcaption>Finding peace in the pages of a good book</figcaption></figure><p>It was a typical Tuesday night. My mind was racing with worries about work, money, and the latest drama on social media. I tried to distract myself by watching a few episodes of my favorite show on Netflix, but even that couldn’t ease my anxiety. I felt like I was on the verge of a breakdown.</p><p>That’s when I remembered the power of books. I dug out an old novel from my bookshelf, dusted it off, and started to read. Within minutes, I was transported to a different world — one where my problems didn’t matter, and I could just focus on the story in front of me.</p><p>As I turned the pages, I felt my mind calm down. The racing thoughts slowed to a gentle hum. The worries that had felt so overwhelming just moments before faded away. And when I finally closed the book and went to bed, I fell asleep feeling peaceful and rejuvenated.</p><blockquote>And it turns out, there’s science to back up the idea that reading can help you stay focused and reduce stress. According to a study conducted by Dr. David Lewis from the University of Sussex, reading for just six minutes can reduce stress levels by up to 68% (2009). This study found that reading can be even more effective at reducing stress than taking a walk, listening to music, or enjoying a cup of tea.</blockquote><blockquote>Another study published in the journal PLOS ONE by researchers from the University of California, Riverside, and Duke University revealed that reading fiction can improve cognitive flexibility and creativity (2013). This research suggests that immersing oneself in a fictional world can have a lasting impact on our cognitive abilities, including concentration and focus.</blockquote><p>But beyond the scientific evidence, there’s something special about the way that reading can help you stay focused. When you’re reading, you’re not multitasking or splitting your attention between different screens or notifications. You’re fully immersed in the story, and your mind can’t help but follow along. It’s a break from the constant stream of stimuli that we’re bombarded with in our digital lives.</p><p>So the next time you’re feeling like you can’t stay focused on anything, try picking up a book. Explore different genres, from fiction to non-fiction, poetry to essays, and see what resonates with you. Create a comfortable reading environment by choosing a quiet, cozy space and setting aside dedicated time for reading. Get lost in a story for a while, and see how it makes you feel. You might be surprised by how much it helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4b8409a93af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chasing Data Dreams: My Road to Becoming a Skilled Analyst]]></title>
            <link>https://medium.com/@afanayubi/my-long-journey-to-become-a-data-analyst-d4bcdff81f9a?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4bcdff81f9a</guid>
            <category><![CDATA[my-story]]></category>
            <category><![CDATA[journey]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[data-analyst]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 02:42:45 GMT</pubDate>
            <atom:updated>2023-04-11T13:17:16.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfvuxWuV8ka2JyTUdL5orw.jpeg" /><figcaption>My lock screen wallpaper to cheer me up</figcaption></figure><p>I left my position as a mechanical engineer at a prominent shoe manufacturing company in Sidoarjo, East Java, Indonesia almost two years ago after working there for four years. Despite my best efforts to adapt to the role, I couldn’t find a compelling reason to stay. I explored various resources such as books, podcasts, and YouTube videos before eventually mustering the courage to resign. After ensuring that I had enough savings to sustain myself for at least three years, I made the decision to leave.</p><p>In July 2021, I left my job. I felt a sense of excitement, freedom, and optimism about the future at that time. This was a major decision in my life, and it made me feel more like an adult, as my parents had always been the ones making decisions for me before. I now realize that I was at fault for not taking responsibility, lacking the courage to face problems, and frequently blaming my parents for things.</p><p>Following my resignation, I embarked on a journey to enroll in a Product Management Bootcamp course, which proved to be a delightful experience. The course involved identifying problems, gathering data, and utilizing our imaginations to enhance products in line with user needs and business objectives. During the program, I had the opportunity to work alongside a mentor and make new friends who shared my passion for learning and becoming a PM.</p><p>After completing the course in December, I set out to create a portfolio and apply for internships or entry-level APM roles. Unfortunately, my background as a mechanical engineer interested in pursuing a career in product management didn’t seem to appeal to potential employers, and I was unable to secure a job.</p><p>In March 2022, I decided to enroll in a data science course, and it was my first time exploring this field. Despite being a novice, I found the subject matter fascinating and was determined to persevere through the challenging material. With diligent effort, I was able to complete the course and earn a certificate.</p><p>In addition to the data science course, I also took several other courses on Udemy, such as Python, website building, product management, photography, and SQL. However, I found it difficult to focus on these courses, as they seemed to lack the structure and guidance I needed to learn effectively. As a result, I struggled to keep up with the material and found it challenging to follow along.</p><p>Last July 2022, I decided to take a data analytics course offered by IBM. Although I found the course material interesting, I encountered many unfamiliar technical terms that were difficult to comprehend, and my limited English proficiency didn’t help matters. Nonetheless, I persevered and completed the course, determined to improve my skills.</p><p>Subsequently, I enrolled in another course, namely the Google Data Analytics Certificate on Coursera. This course proved to be an incredibly engaging and enjoyable learning experience for me. The material was presented in an appealing and accessible manner, and the instructors made an effort to connect with me and encourage me to develop my data analytics skills. Despite the length and complexity of the course — it involved completing eight separate courses — I was able to finish it in December 2022.</p><p>Despite completing the Google Data Analytics courses, I still felt that I lacked a tangible project to showcase my skills as a data analyst. From January 2023 until March 2023, I struggled to develop a portfolio project that would demonstrate my capabilities to potential employers. However, I found the process challenging, and often felt alone and intimidated by the prospect of seeking out a mentor or assistance.</p><p>Finally, in April 2023, I successfully completed my first case study project using Python, which gave me a sense of pride and accomplishment. I sought the help of ChatGPT to clarify and correct any syntax errors, which proved to be an invaluable resource. Although I have yet to secure my first job as a data analyst, I am thrilled to have completed a project and look forward to using it as a showcase of my skills and capabilities.</p><blockquote>Studying programming languages like Python, R, and SQL has taught me the importance of accepting failure as an essential component of the learning journey. I have come to realize that it is perfectly normal to make errors and experience setbacks while acquiring new skills, as these experiences have helped me develop a greater sense of confidence and a willingness to experiment and try new things until I achieve success.</blockquote><p>As I reflect on my journey over the past two years, I realize that I have discovered a deep passion for the field of data and a strong desire to pursue it as a career. While I experience moments of anxiety and apprehension, I understand that my parents are concerned about my future and have my best interests at heart. Nonetheless, I sometimes feel like a failure when I compare myself to my peers, many of whom have stable jobs and families, while I continue to seek my first job as a data analyst intern or junior data analyst.</p><p>Despite these challenges, I remain committed to my goals and am determined to find a job that allows me to pursue my passion for data. I am confident that my persistence and hard work will eventually pay off, and I look forward to beginning my career in a field that excites and motivates me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4bcdff81f9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Calculate Mode in BigQuery]]></title>
            <link>https://medium.com/@afanayubi/calculate-mode-in-bigquery-57bb7c6072e9?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/57bb7c6072e9</guid>
            <category><![CDATA[query]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[mode]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 18:13:19 GMT</pubDate>
            <atom:updated>2023-03-27T18:13:19.288Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TlCmncnPZeS0IJFvqSh4JQ.png" /></figure><p>Mode, mean and median are three commonly used measures of central tendency in statistics. They are used to describe the typical or central value of a set of data. The mode is useful for identifying the most frequently occurring value or identifying the peak of a distribution. It is the value that appears the most number of times. A dataset can have one mode, multiple modes, or no mode at all. For example, the mode of the numbers 2, 2, 4, 6, and 8 is 2. In BigQuery there is no function to calculate the mode from the data that we have, Here I will demonstrate step by step how I calculate the mode.</p><h3>Overview</h3><p>In this case, the goal is to determine the age of subscribers who frequently use cycling apps. The relevant data for this investigation is limited to the first, second, third, and fourth quarters of 2015. To achieve this, I have downloaded the data <a href="https://divvy-tripdata.s3.amazonaws.com/index.html">here</a> and combined it into a single table called “df_customer_2015”. The code used to accomplish this is provided below, and the resulting figure is displayed in figure 1.</p><pre>SELECT age, COUNT(age) AS total_user<br>FROM (<br>  SELECT *, CAST((2023-birthyear)AS STRING) AS age<br>  FROM `case-study-1-368807.CaseStudy1.df_customer_2015`<br>  WHERE usertype = &#39;Subscriber&#39; and gender is not NULL and birthyear is not NULL )<br>GROUP BY age<br>ORDER BY COUNT(age) DESC</pre><h3>EXPLANATION</h3><p>Let’s break down how to query it in two steps.</p><p>STEP 1:</p><ul><li>Initially, my intention is to display all of the columns contained within the table, and this can be achieved by utilizing the “SELECT *” command.</li><li>Subsequently, I aim to determine the age of the customers by subtracting their birth year from the year 2023 and labeling the resulting column as “age”.</li><li>To accomplish this, I will utilize data FROM the dataset named `case-study-1–368807.CaseStudy1.df_customer_2015`.</li><li>Additionally, I will employ filters in the WHERE clause to only consider customers who are subscribers and gender is not NULL and birthyear is not NULL</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*09Xs_cgPePoBViQVV0w3cw.png" /><figcaption>Figure 1. Syntax and Result</figcaption></figure><p>STEP2:</p><ul><li>SELECT age, and then summarize the age by COUNT syntax and name it a column total_user.</li><li>Next, we want the data FROM the query that we already made before, that’s why put the query in step one to this FROM statement.</li><li>And then I want to Group it by age and order by total_user DESC</li><li>If you execute this program and receive the total count of subscribers, you must modify the data type of the “age” column using the CAST function. Currently, the “age” column is represented as an integer, but we desire it to be a string. You can refer to figure 2 for the syntax of the CAST function.</li></ul><p>RESULT:</p><ul><li>After analyzing 2,253,413 data entries within the age range of 24 to 125 years, we determined that the most common age group among subscribers who use bicycles are individuals who are 37 years old. Specifically, there were 131,184 users within this age group.</li><li>the result is from all gender, If you want to analyze it per gender you can add gender in the SELECT statement and GROUP BY statement.</li></ul><h3>CONCLUSION</h3><ul><li>To determine the mode of a given range of data, you need to first convert the relevant column into a STRING data type. Then, you can use the COUNT function to identify the frequency of each data point. Once this is done, you can GROUP the data and arrange it in descending order using the ORDER BY clause.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57bb7c6072e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Separate Date and Time in Bigquery]]></title>
            <link>https://medium.com/@afanayubi/separate-date-and-time-in-bigquery-8042ebd21a79?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8042ebd21a79</guid>
            <category><![CDATA[date-and-time]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[extract]]></category>
            <category><![CDATA[query]]></category>
            <category><![CDATA[timestamp]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Sat, 25 Mar 2023 15:48:50 GMT</pubDate>
            <atom:updated>2023-03-27T07:45:47.322Z</atom:updated>
            <content:encoded><![CDATA[<p>In BigQuery, you can separate date and time from a timestamp field using the EXTRACT function. Here is an example. If we want to extract the timestamp data type column as in figure 1. Let’s separate timestamps from column start to day_of_year, day_of_week, month, week, iso_week, iso_year, and year using EXTRACT. The syntax is in the code block below.</p><pre>EXTRACT(part FROM timestamp_expression [AT TIME ZONE time_zone])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*ghYnMkCh_Px4wEiiWXwh5g.png" /><figcaption>Figure 1. Timestamp Table</figcaption></figure><p>Here is the code block that I used to separate timestamp</p><pre>SELECT <br>  id, start,<br>  EXTRACT(DAYOFYEAR FROM start) AS day_of_year,<br>  EXTRACT(DAYOFWEEK FROM start) AS day_of_week,<br>  EXTRACT(MONTH FROM start) as month,<br>  EXTRACT(WEEK FROM start) as week,<br>  EXTRACT(ISOWEEK FROM start) as iso_week,<br>  EXTRACT(ISOYEAR FROM start) as iso_year,<br>  EXTRACT(YEAR FROM start) as year<br>FROM `case-study-1-368807.CaseStudy1.df_departure`</pre><p>The Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvMSiG7x5GPlMEE671E4uw.png" /><figcaption>Figure 2. Query Result</figcaption></figure><p>Explanation:</p><ul><li>day_of_year is converted from the date to the number of days in a year (1–365/366). exp 2022–03–05 is the 64th day of the year 2022.</li><li>day_of_week is converted from the date number of days in a week (1–7) starting from Sunday, so 1 = Sunday, 7 = Saturday.</li><li>month is extracting to month from date.</li><li>week is the number of weeks in a year (1–52).</li><li>iso_week: Returns the <a href="https://en.wikipedia.org/wiki/ISO_week_date">ISO 8601 week</a> number of the date_expression.isoweek begins on Monday, and Return values are in the range [1, 53]. The first isoweek of each ISO year begins on the Monday before the first Thursday of the Gregorian calendar year.</li><li>year is the year from the date in the timestamp.</li><li>isoyear: Returns the <a href="https://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> week-numbering year, which is the Gregorian calendar year containing the Thursday of the week to which date_expression belongs.</li></ul><p>Conclusion :</p><ul><li>Use EXTRACT to convert the timestamp type of data to the unit that you needed.</li><li>The syntax from EXTRACT is EXTRACT(part FROM column).</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8042ebd21a79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Calculate the Distance using Longitude and Latitude in BigQuery]]></title>
            <link>https://medium.com/@afanayubi/calculate-the-distance-using-longitude-and-latitude-in-bigquery-d4110ee247c6?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4110ee247c6</guid>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[distance]]></category>
            <category><![CDATA[latitude-and-longitude]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Sat, 25 Mar 2023 07:40:49 GMT</pubDate>
            <atom:updated>2023-03-25T07:40:49.654Z</atom:updated>
            <content:encoded><![CDATA[<p>Calculate the distance between two points on the Earth’s surface using their longitude and latitude. Latitude refers to the horizontal lines that run east-west and measure the distance of a location north or south of the Equator. Longitude refers to the vertical lines that run north-south and measure the distance of a location east or west of the Prime Meridian, an imaginary line that runs through the Royal Observatory in Greenwich, London, England. Together, longitude and latitude provide a precise location for any point on Earth’s surface, allowing for easy navigation and mapping. To calculate between two points we can use use the syntax ST_DISTANCE in BigQuery. ST_DISTANCE syntax is in figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*alVoUJZPIAsC2qyQFYNdLw.png" /><figcaption>figure 1. ST_DISTANCE syntax</figcaption></figure><p>Using ST_DISTANCE syntax we need to put the point as addressed so the ST_DISTANCE need followed by ST_GEOGPOINT. The syntax is in figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*wLJstqJBGWePzd8GQJPh4A.png" /><figcaption>Figure 2. ST_GEOGPOINT syntax</figcaption></figure><p>To use the syntax, let&#39;s try to apply it to the table in figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqIq8ZDZGOGiPE9RX0o9aA.png" /><figcaption>Figure 3. start — end distance point</figcaption></figure><p>Here is the code block that I use to calculate the distance between the start and end latitude and longitude from figure 3.</p><pre>SELECT <br>  *,<br>  ST_DISTANCE(ST_GEOGPOINT(start_lng, start_lat), ST_GEOGPOINT(end_lng, end_lat), FALSE) AS distance_in_m<br>FROM `case-study-1-368807.CaseStudy1.distance_calculation`</pre><p>The optional USE_SPHEROID is in figure 1. ST_DISTANCE syntax means the parameter determines how this function measures distance. If USE_SPHEROID is FALSE, the function measures distance on the surface of a perfect sphere. If USE_SPHEROID is TRUE, the function measures distance on the surface of the <a href="https://en.wikipedia.org/wiki/World_Geodetic_System">WGS84</a> spheroid. The default value of USE_SPHEROID is FALSE. Here is the different result if using USE_SPHEROID in figure 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzX_kkUnbATQ-qfNOQPaBw.png" /><figcaption>Figure 4. The result</figcaption></figure><p>Conclusion:</p><ul><li>Use ST_DISTANCE to calculate two different longitudes and latitudes.</li><li>Use ST_GEOGPOINT to address the point of latitude and longitude.</li><li>USE_SPHEROID FALSE or TRUE to calculate it by the default distance or by WGS84.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4110ee247c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Identify the time differences between a start and end point using BigQuery]]></title>
            <link>https://medium.com/@afanayubi/time-diff-vs-date-diff-in-bigquery-afecdc9b85c5?source=rss-2222ca51ccd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/afecdc9b85c5</guid>
            <category><![CDATA[query]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[date-calculation]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[time-difference]]></category>
            <dc:creator><![CDATA[Afan Annur Ayubi]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 15:14:57 GMT</pubDate>
            <atom:updated>2023-03-27T18:17:38.979Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I have been processing TIMESTAMP type of data. In SQL, the TIMESTAMP data type is used to store date and time values in a specific format. It is represented as a combination of a date and a time and is generally used to track changes to records in a database. In this case, I would share my experience using TIME_DIFF and DATE_DIFF in BigQuery. TIME_DIFF and DATE_DIFF use to calculate the difference time. Example in figure 1. We want to know how much time difference between the start and ended from time data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDd2km83Ii6zlrsJkwmmqA.png" /><figcaption>Figure 1. Time Data</figcaption></figure><p>If we want to calculate how much time the data between ended and start we could use TIME_DIFF or DATE_DIFF. Here is the code that I use to calculate the time difference between them. I use 3 different methods, to calculate which is TIME_DIFF, DATE_DIFF, and another one I used the minus operator ( — ).</p><pre>SELECT <br>  *,<br>  TIME_DIFF(TIME(ended), TIME(start), minute) AS time_different,<br>  DATETIME_DIFF(DATETIME(ended), DATETIME(start), minute) AS date_different,<br>  (ended - start) AS operator_different,<br>FROM `case-study-1-368807.CaseStudy1.df_departure`</pre><p>First, Let’s start to reveal the query.</p><ul><li>In the SELECT statement I want to call all the data that’s why I use *</li><li>Next, I use time TIME_DIFF followed by (TIME(ended), TIME(start), and minute) after that I name this column time_different. When writing the TIME_DIFF statement, will be shown in figure 2.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*Ky8bahFb0wALEHFEGDXrBg.png" /><figcaption>figure 2. TIME_DIFF Syntax</figcaption></figure><ul><li>Note: You must put ended column as time_expression_a followed by TIME which means ended column is part of the time. If you put start first, the result would be minus ( — ), and the last syntax is part. Part of is unit of the calculation will be presented. it can be the second, minute, hour, etc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*1z6XiSNlRVFu2pKyCjIemw.png" /><figcaption>Figure 3. DATE_DIFF Syntax</figcaption></figure><ul><li>Next, for the DATE_DIFF syntax shown in figure 3. the explanation same as TIME_DIFF, the difference is they use the DATETIME followed by the column to address the column as date time. If using just DATE, it will be an error and the query can’t be run. You can check the query that I made in the query block above.</li><li>And the last one is I use the minus operator to directly calculate from ended and start which I name operator_different.</li></ul><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0KEtbA9sKRyyfMB2UOb3Q.png" /><figcaption>Figure 4. Result from Query</figcaption></figure><p>The result in Figure 4. shows that there is a difference between them. But if you see the start column and ended column, to make sure of the result you will see the differences.</p><ul><li>TIME_DIFF only shows the result of the differences between the two times. TIME_DIFF expression didn’t calculate the result if the date changed.</li><li>Meanwhile, DATE_DIFF is more complex. the result shows the difference between both the date and time to convert into the unit that we want to present.</li><li>So, what is the difference with the operator? The result of using the minus operator is also correct, the difference is in the type of data. Using DATE_DIFF the result would be an integer and using the minus operator the type of data interval.</li></ul><p>CONCLUSION</p><ul><li>If you want to know about the difference between the two types of TIMESTAMP data, I suggest using DATE_DIFF if the column includes dates and times.</li><li>Use TIME_DIFF if the data is just time without a date.</li><li>If you want the type of data as an interval, just use the operator minus to know the differences.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afecdc9b85c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>