options(repos = c(CRAN = "https://cran.rstudio.com/"))
install.packages("tidyverse")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("lubridate")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("tibble")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("ggplot2")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("readr")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("dplyr")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("janitor")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("skimr")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
install.packages("graphics")
## Warning: package 'graphics' is a base package, and should not be updated
install.packages("png")
## 
## The downloaded binary packages are in
##  /var/folders/w0/b9x6g4tj73q6hkcqj6l6g80h0000gn/T//RtmpGAESFK/downloaded_packages
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.3.1
## Warning: package 'dplyr' was built under R version 4.3.1
## Warning: package 'lubridate' was built under R version 4.3.1
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(tibble)
library(ggplot2)
library(readr)
library(dplyr)
library(janitor)
## 
## Attaching package: 'janitor'
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(skimr)
library(graphics)
library(png)

##Using different language

In case we use another default language different from English, you should run this line. This is important because we’ll be working with days of the week as text strings and date-times

Sys.setlocale("LC_TIME", "en_US")
## [1] "en_US"
image_path <- "/Users/divyaramesh/Documents/Data Analyst Courses/Google Data Analytics Professional Certificate/Case Study Data Analytics/Picture1.png"
img <- readPNG(image_path)
plot.new()
graphics::rasterImage(img, 0, 0, 1, 1)

INTRODUCTION

As a junior data analyst within Cyclistic, a Chicago-based bike-share company, I am part of the marketing analyst team. Our current focus is on comprehending the distinctions in bike usage patterns between casual riders and annual members. The director of marketing asserts that the company’s future success hinges on optimizing annual memberships. Consequently, our team aims to derive insights into how casual riders and annual members utilize Cyclistic bikes differently. The intention is to utilize these insights to formulate a new marketing strategy geared towards converting casual riders into annual members. To achieve this, the project will follow the steps of the data analysis process: ask, prepare, process, analyze, share, and act. Moreover, it is imperative that our recommendations are substantiated by compelling data insights and presented through professional data visualizations, as approval from Cyclistic executives is a prerequisite.

ABOUT THE COMPANY

In 2016, Cyclistic launched a successful bike-share offering. Since then, the program has grown to a fleet of 5,824 bicycles that are geotracked and locked into a network of 692 stations across Chicago. The bikes can be unlocked from one station and returned to any other station in the system anytime. Until now, Cyclistic’s marketing strategy relied on building general awareness and appealing to broad consumer segments. One approach that helped make these things possible was the flexibility of its pricing plans: single-ride passes, full-day passes, and annual memberships. Customers who purchase single-ride or full-day passes are referred to as casual riders. Customers who purchase annual memberships are Cyclistic members. Cyclistic’s finance analysts have concluded that annual members are much more profitable than casual riders. Although the pricing flexibility helps Cyclistic attract more customers, Moreno believes that maximizing the number of annual members will be key to future growth. Rather than creating a marketing campaign that targets all-new customers, Moreno believes there is a very good chance to convert casual riders into members. She notes that casual riders are already aware of the Cyclistic program and have chosen Cyclistic for their mobility needs. Moreno has set a clear goal: Design marketing strategies aimed at converting casual riders into annual members. In order to do that, however, the marketing analyst team needs to better understand how annual members and casual riders differ, why casual riders would buy a membership, and how digital media could affect their marketing tactics. Moreno and her team are interested in analyzing the Cyclistic historical bike trip data to identify trends.

ASK

This phase involves defining the issue to be solved, identifying stakeholders and what their expectations from the project are. Three questions will guide the future marketing program: 1. How do annual members and casual riders use Cyclistic bikes differently? 2. Why would casual riders buy Cyclistic annual memberships? 3. How can Cyclistic use digital media to influence casual riders to become members?

BUSINESS TASK

The primary business task is to understand how annual members and casual riders utilize Cyclistic bikes differently. This analysis aims to provide insights that will inform the development of a targeted marketing strategy to convert casual riders into annual members.

DATA SOURCES

The main data source for this analysis is the Cyclistic historical bike trip data. The dataset includes information on bike trips, user types (annual member or casual rider), trip duration, start and end stations, and other relevant variables. Additionally, demographic data and digital media interactions may be considered if available.

KEY DEFINITION

Cyclistic: A bike-share program that features more than 5,800 bicycles and 600 docking stations. Cyclistic sets itself apart by also offering reclining bikes, hand tricycles, and cargo bikes, making bike-share more inclusive to people with disabilities and riders who can’t use a standard two-wheeled bike. The majority of riders opt for traditional bikes; about 8% of riders use the assistive options. Cyclistic users are more likely to ride for leisure, but about 30% use them to commute to work each day. Casuals: Customers who purchase single-ride or full-day passes. Members: Customers who purchase annual memberships are Cyclistic members.

PREPARE

Involves collecting data and information and ensuring it satisfies necessary parameters. ## DATA LOCATION, LICENSING AND PRIVACY The data has been made available by Motivate International Inc. at this link under this license. For privacy purposes riders personally identifiable information has been excluded from the data. ## DATA ORGANIZATION The data used for this analysis is the past 10 months from January 2023 to October 2023. Each month contains hundreds of thousands of rows and 13 columns. ## BIAS AND CREDIBILITY The data satisfies the ROCCC standard which means that it is reliable, original, comprehensive, current and cited. ## DATA LIMITATIONS The dataset contains some null values that were deleted and hence not used in the analysis.

PROCESS

This phase of the analysis process includes cleaning the data and making sure it is fit for purpose. As well as making any modifications necessary.

Rstudio was used for the data processing phase of this project.
A summary of the cleaning and manipulation done to the data is presented below: 1. Combined all 10 individual months into a single data frame called “totalyear_2023”. 2. Created new columns to extract the day, month, year and day of the week of each ride entry. 3. Created a new column calculating the length of each ride from the difference between the recorded “end_time” and “start_time” of each ride entry. 4. Changed the “ride_length” from time datatype to numeric datatype. 5. Deleted all the rows in the data frame with a null entry. 6. Deleted entries with ride length less than zero. 7. Created a new data frame where the “started_at” and “ended_at” locations were combined to get an aggregate route of each ride/trip.

Here the Data Cleaning and other process is been started in RStudio

Load the datasets

There are a total of 10 CSV files, each corresponding to every month in the year 2023. To set the path to the working directory, you can use the setwd() function.

knitr::opts_knit$set(root.dir = "/Users/divyaramesh/Documents/Data Analyst Courses/Google Data Analytics Professional Certificate/Case Study Data Analytics/CSV Files")

Read 10 CSV files

Reading the csv files from the directory which we set before. We use the tibble() function to check if the CSV file data is read. why tibble? This is because tibble() ensures that the data fits into the screen.

january_2023 <- read.csv("202301-divvy-tripdata.csv")
tibble(january_2023)
## # A tibble: 190,301 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 F96D5A… electric_bike 2023-01-2… 2023-01… Lincoln Ave & Ful… TA1309000058    
##  2 13CB7E… classic_bike  2023-01-1… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  3 BD88A2… electric_bike 2023-01-0… 2023-01… Western Ave & Lun… RP-005          
##  4 C90792… classic_bike  2023-01-2… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  5 339701… classic_bike  2023-01-1… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  6 58E681… electric_bike 2023-01-3… 2023-01… Lakeview Ave & Fu… TA1309000019    
##  7 2F7194… electric_bike 2023-01-1… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  8 DB1CF8… classic_bike  2023-01-2… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  9 34EAB9… electric_bike 2023-01-2… 2023-01… Kimbark Ave & 53r… TA1309000037    
## 10 BC8AB1… classic_bike  2023-01-0… 2023-01… Kimbark Ave & 53r… TA1309000037    
## # ℹ 190,291 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
february_2023 <- read.csv("202302-divvy-tripdata.csv")
tibble(february_2023)
## # A tibble: 190,445 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 CBCD0D… classic_bike  2023-02-1… 2023-02… Southport Ave & C… TA1309000030    
##  2 F3EC5F… electric_bike 2023-02-1… 2023-02… Clarendon Ave & G… 13379           
##  3 E54C1F… classic_bike  2023-02-1… 2023-02… Southport Ave & C… TA1309000030    
##  4 3D561E… electric_bike 2023-02-2… 2023-02… Southport Ave & C… TA1309000030    
##  5 0CB4B4… electric_bike 2023-02-2… 2023-02… Prairie Ave & Gar… TA1307000160    
##  6 C67EB6… classic_bike  2023-02-2… 2023-02… Wells St & Concor… TA1308000050    
##  7 08A1E9… classic_bike  2023-02-2… 2023-02… Wells St & Concor… TA1308000050    
##  8 904C61… classic_bike  2023-02-2… 2023-02… Wells St & Concor… TA1308000050    
##  9 A96A6D… classic_bike  2023-02-0… 2023-02… Wells St & Concor… TA1308000050    
## 10 DA895A… classic_bike  2023-02-2… 2023-02… Wells St & Concor… TA1308000050    
## # ℹ 190,435 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
march_2023 <- read.csv("202303-divvy-tripdata.csv")
tibble(march_2023)
## # A tibble: 258,678 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 6842AA… electric_bike 2023-03-1… 2023-03… Clark St & Armita… 13146           
##  2 F98426… electric_bike 2023-03-0… 2023-03… Public Rack - Ked… 491             
##  3 FF7CF5… classic_bike  2023-03-3… 2023-03… Orleans St & Ches… 620             
##  4 6B61B9… classic_bike  2023-03-2… 2023-03… Desplaines St & K… TA1306000003    
##  5 E55E61… electric_bike 2023-03-0… 2023-03… Walsh Park         18067           
##  6 123AAD… classic_bike  2023-03-2… 2023-03… Orleans St & Ches… 620             
##  7 5929D3… classic_bike  2023-03-0… 2023-03… Rush St & Hubbard… KA1503000044    
##  8 B2624B… docked_bike   2023-03-2… 2023-03… Adler Planetarium  13431           
##  9 979C41… classic_bike  2023-03-1… 2023-03… Broadway & Wilson… 13074           
## 10 6C1DCA… classic_bike  2023-03-1… 2023-03… Stetson Ave & Sou… TA1308000029    
## # ℹ 258,668 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
april_2023 <- read.csv("202304-divvy-tripdata.csv")
tibble(april_2023)
## # A tibble: 426,590 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 8FE8F7… electric_bike 2023-04-0… 2023-04… ""                 ""              
##  2 34E4ED… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  3 5296BF… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  4 407599… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  5 77A96F… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  6 8D6A23… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  7 C97BBA… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  8 6687AD… electric_bike 2023-04-1… 2023-04… ""                 ""              
##  9 A8FA4F… electric_bike 2023-04-1… 2023-04… ""                 ""              
## 10 81E158… electric_bike 2023-04-1… 2023-04… ""                 ""              
## # ℹ 426,580 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
may_2023 <- read.csv("202305-divvy-tripdata.csv")
tibble(may_2023)
## # A tibble: 604,827 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 0D9FA9… electric_bike 2023-05-0… 2023-05… Southport Ave & B… 13229           
##  2 92485E… electric_bike 2023-05-0… 2023-05… Southport Ave & B… 13229           
##  3 FB144B… electric_bike 2023-05-2… 2023-05… Halsted St & 21st… 13162           
##  4 DDEB93… classic_bike  2023-05-1… 2023-05… Carpenter St & Hu… 13196           
##  5 C07B70… classic_bike  2023-05-0… 2023-05… Southport Ave & C… TA1308000047    
##  6 2BA663… classic_bike  2023-05-3… 2023-05… Clinton St & Madi… TA1305000032    
##  7 31EFCC… docked_bike   2023-05-0… 2023-05… DuSable Lake Shor… 13300           
##  8 71DFF8… classic_bike  2023-05-0… 2023-05… Shore Dr & 55th St TA1308000009    
##  9 211748… classic_bike  2023-05-1… 2023-05… Clark St & Schill… TA1309000024    
## 10 811149… electric_bike 2023-05-1… 2023-05… Clinton St & Madi… TA1305000032    
## # ℹ 604,817 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
june_2023 <- read.csv("202306-divvy-tripdata.csv")
tibble(june_2023)
## # A tibble: 719,618 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 6F1682… electric_bike 2023-06-0… 2023-06… ""                 ""              
##  2 622A16… electric_bike 2023-06-0… 2023-06… ""                 ""              
##  3 3C8885… electric_bike 2023-06-2… 2023-06… ""                 ""              
##  4 EAD8A5… electric_bike 2023-06-1… 2023-06… ""                 ""              
##  5 5A36F2… electric_bike 2023-06-1… 2023-06… ""                 ""              
##  6 CF682E… electric_bike 2023-06-0… 2023-06… ""                 ""              
##  7 4910FB… electric_bike 2023-06-0… 2023-06… ""                 ""              
##  8 EA19D8… electric_bike 2023-06-0… 2023-06… ""                 ""              
##  9 E68F43… electric_bike 2023-06-0… 2023-06… ""                 ""              
## 10 5A013E… electric_bike 2023-06-0… 2023-06… ""                 ""              
## # ℹ 719,608 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
july_2023 <- read.csv("202307-divvy-tripdata.csv")
tibble(july_2023)
## # A tibble: 767,650 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 9340B0… electric_bike 2023-07-2… 2023-07… Kedzie Ave & 110t… 20204           
##  2 D1460E… classic_bike  2023-07-2… 2023-07… Western Ave & Wal… KA1504000103    
##  3 DF41BE… classic_bike  2023-07-2… 2023-07… Western Ave & Wal… KA1504000103    
##  4 9624A2… electric_bike 2023-07-2… 2023-07… Racine Ave & Rand… 13155           
##  5 2F68A6… classic_bike  2023-07-0… 2023-07… Clark St & Leland… TA1309000014    
##  6 9AEE97… classic_bike  2023-07-1… 2023-07… Racine Ave & Rand… 13155           
##  7 E366E9… classic_bike  2023-07-2… 2023-07… Clark St & Leland… TA1309000014    
##  8 1BB3E7… classic_bike  2023-07-0… 2023-07… Clark St & Leland… TA1309000014    
##  9 DA1E1D… electric_bike 2023-07-0… 2023-07… Clark St & Leland… TA1309000014    
## 10 39BF4A… classic_bike  2023-07-2… 2023-07… Warren Park East   RP-002          
## # ℹ 767,640 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
august_2023 <- read.csv("202308-divvy-tripdata.csv")
tibble(august_2023)
## # A tibble: 771,693 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 903C30… electric_bike 2023-08-1… 2023-08… LaSalle St & Illi… 13430           
##  2 F2FB18… electric_bike 2023-08-1… 2023-08… Clark St & Randol… TA1305000030    
##  3 D0DEC7… electric_bike 2023-08-3… 2023-08… Clark St & Randol… TA1305000030    
##  4 E0DDDC… electric_bike 2023-08-3… 2023-08… Wells St & Elm St  KA1504000135    
##  5 7797A4… electric_bike 2023-08-2… 2023-08… Clark St & Randol… TA1305000030    
##  6 DF4DE7… electric_bike 2023-08-2… 2023-08… Milwaukee Ave & F… 428             
##  7 EE60FB… electric_bike 2023-08-3… 2023-08… Milwaukee Ave & F… 428             
##  8 A115DA… electric_bike 2023-08-1… 2023-08… Orleans St & Merc… TA1305000022    
##  9 86DBB1… electric_bike 2023-08-2… 2023-08… Milwaukee Ave & F… 428             
## 10 2905CB… electric_bike 2023-08-2… 2023-08… Orleans St & Merc… TA1305000022    
## # ℹ 771,683 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
september_2023 <- read.csv("202309-divvy-tripdata.csv")
tibble(september_2023)
## # A tibble: 666,371 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 011C19… classic_bike  2023-09-2… 2023-09… Halsted St & Wrig… TA1309000061    
##  2 87DB80… classic_bike  2023-09-0… 2023-09… Clark St & Drummo… TA1307000142    
##  3 7C2EB7… electric_bike 2023-09-2… 2023-09… Financial Pl & Id… SL-010          
##  4 57D197… classic_bike  2023-09-1… 2023-09… Clark St & Drummo… TA1307000142    
##  5 8A2CEA… classic_bike  2023-09-1… 2023-09… Halsted St & Wrig… TA1309000061    
##  6 03F704… electric_bike 2023-09-1… 2023-09… Southport Ave & W… TA1307000113    
##  7 672503… electric_bike 2023-09-2… 2023-09… Kedzie Ave & Milw… 13085           
##  8 1D8064… electric_bike 2023-09-1… 2023-09… Jeffery Blvd & 71… KA1503000018    
##  9 40D9EF… classic_bike  2023-09-1… 2023-09… Kedzie Ave & Milw… 13085           
## 10 C60CE6… electric_bike 2023-09-0… 2023-09… Southport Ave & W… TA1307000113    
## # ℹ 666,361 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
october_2023 <- read.csv("202310-divvy-tripdata.csv")
tibble(october_2023)
## # A tibble: 537,108 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 3CB26D… electric_bike 2023-10-0… 2023-10… Ashland Ave & Bla… 13224           
##  2 099502… classic_bike  2023-10-1… 2023-10… Southport Ave & C… TA1308000047    
##  3 A97914… classic_bike  2023-10-0… 2023-10… DuSable Lake Shor… 13300           
##  4 1780A2… classic_bike  2023-10-0… 2023-10… Streeter Dr & Gra… 13022           
##  5 59C533… classic_bike  2023-10-2… 2023-10… Sheffield Ave & W… TA1307000052    
##  6 F1A499… electric_bike 2023-10-0… 2023-10… Clinton St & Madi… TA1305000032    
##  7 CC230A… electric_bike 2023-10-3… 2023-10… Southport Ave & B… 13229           
##  8 600579… classic_bike  2023-10-1… 2023-10… Southport Ave & B… 13229           
##  9 557BBD… classic_bike  2023-10-1… 2023-10… Halsted St & 21st… 13162           
## 10 62579A… classic_bike  2023-10-2… 2023-10… Clark St & Schill… TA1309000024    
## # ℹ 537,098 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>

Ready for Analysis

It is important to verify the consistency of column names and variable types. You can check the structure of each dataset by running the following lines of code.

str(january_2023)
## 'data.frame':    190301 obs. of  13 variables:
##  $ ride_id           : chr  "F96D5A74A3E41399" "13CB7EB698CEDB88" "BD88A2E670661CE5" "C90792D034FED968" ...
##  $ rideable_type     : chr  "electric_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : chr  "2023-01-21 20:05:42" "2023-01-10 15:37:36" "2023-01-02 07:51:57" "2023-01-22 10:52:58" ...
##  $ ended_at          : chr  "2023-01-21 20:16:33" "2023-01-10 15:46:05" "2023-01-02 08:05:11" "2023-01-22 11:01:44" ...
##  $ start_station_name: chr  "Lincoln Ave & Fullerton Ave" "Kimbark Ave & 53rd St" "Western Ave & Lunt Ave" "Kimbark Ave & 53rd St" ...
##  $ start_station_id  : chr  "TA1309000058" "TA1309000037" "RP-005" "TA1309000037" ...
##  $ end_station_name  : chr  "Hampden Ct & Diversey Ave" "Greenwood Ave & 47th St" "Valli Produce - Evanston Plaza" "Greenwood Ave & 47th St" ...
##  $ end_station_id    : chr  "202480.0" "TA1308000002" "599" "TA1308000002" ...
##  $ start_lat         : num  41.9 41.8 42 41.8 41.8 ...
##  $ start_lng         : num  -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ end_lat           : num  41.9 41.8 42 41.8 41.8 ...
##  $ end_lng           : num  -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr  "member" "member" "casual" "member" ...
str(february_2023)
## 'data.frame':    190445 obs. of  13 variables:
##  $ ride_id           : chr  "CBCD0D7777F0E45F" "F3EC5FCE5FF39DE9" "E54C1F27FA9354FF" "3D561E04F739CC45" ...
##  $ rideable_type     : chr  "classic_bike" "electric_bike" "classic_bike" "electric_bike" ...
##  $ started_at        : chr  "2023-02-14 11:59:42" "2023-02-15 13:53:48" "2023-02-19 11:10:57" "2023-02-26 16:12:05" ...
##  $ ended_at          : chr  "2023-02-14 12:13:38" "2023-02-15 13:59:08" "2023-02-19 11:35:01" "2023-02-26 16:39:55" ...
##  $ start_station_name: chr  "Southport Ave & Clybourn Ave" "Clarendon Ave & Gordon Ter" "Southport Ave & Clybourn Ave" "Southport Ave & Clybourn Ave" ...
##  $ start_station_id  : chr  "TA1309000030" "13379" "TA1309000030" "TA1309000030" ...
##  $ end_station_name  : chr  "Clark St & Schiller St" "Sheridan Rd & Lawrence Ave" "Aberdeen St & Monroe St" "Franklin St & Adams St (Temp)" ...
##  $ end_station_id    : chr  "TA1309000024" "TA1309000041" "13156" "TA1309000008" ...
##  $ start_lat         : num  41.9 42 41.9 41.9 41.8 ...
##  $ start_lng         : num  -87.7 -87.6 -87.7 -87.7 -87.6 ...
##  $ end_lat           : num  41.9 42 41.9 41.9 41.8 ...
##  $ end_lng           : num  -87.6 -87.7 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr  "casual" "casual" "member" "member" ...
str(march_2023)
## 'data.frame':    258678 obs. of  13 variables:
##  $ ride_id           : chr  "6842AA605EE9FBB3" "F984267A75B99A8C" "FF7CF57CFE026D02" "6B61B916032CB6D6" ...
##  $ rideable_type     : chr  "electric_bike" "electric_bike" "classic_bike" "classic_bike" ...
##  $ started_at        : chr  "2023-03-16 08:20:34" "2023-03-04 14:07:06" "2023-03-31 12:28:09" "2023-03-22 14:09:08" ...
##  $ ended_at          : chr  "2023-03-16 08:22:52" "2023-03-04 14:15:31" "2023-03-31 12:38:47" "2023-03-22 14:24:51" ...
##  $ start_station_name: chr  "Clark St & Armitage Ave" "Public Rack - Kedzie Ave & Argyle St" "Orleans St & Chestnut St (NEXT Apts)" "Desplaines St & Kinzie St" ...
##  $ start_station_id  : chr  "13146" "491" "620" "TA1306000003" ...
##  $ end_station_name  : chr  "Larrabee St & Webster Ave" "" "Clark St & Randolph St" "Sheffield Ave & Kingsbury St" ...
##  $ end_station_id    : chr  "13193" "" "TA1305000030" "13154" ...
##  $ start_lat         : num  41.9 42 41.9 41.9 41.9 ...
##  $ start_lng         : num  -87.6 -87.7 -87.6 -87.6 -87.7 ...
##  $ end_lat           : num  41.9 42 41.9 41.9 41.9 ...
##  $ end_lng           : num  -87.6 -87.7 -87.6 -87.7 -87.7 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(april_2023)
## 'data.frame':    426590 obs. of  13 variables:
##  $ ride_id           : chr  "8FE8F7D9C10E88C7" "34E4ED3ADF1D821B" "5296BF07A2F77CB5" "40759916B76D5D52" ...
##  $ rideable_type     : chr  "electric_bike" "electric_bike" "electric_bike" "electric_bike" ...
##  $ started_at        : chr  "2023-04-02 08:37:28" "2023-04-19 11:29:02" "2023-04-19 08:41:22" "2023-04-19 13:31:30" ...
##  $ ended_at          : chr  "2023-04-02 08:41:37" "2023-04-19 11:52:12" "2023-04-19 08:43:22" "2023-04-19 13:35:09" ...
##  $ start_station_name: chr  "" "" "" "" ...
##  $ start_station_id  : chr  "" "" "" "" ...
##  $ end_station_name  : chr  "" "" "" "" ...
##  $ end_station_id    : chr  "" "" "" "" ...
##  $ start_lat         : num  41.8 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num  -87.6 -87.7 -87.7 -87.7 -87.7 ...
##  $ end_lat           : num  41.8 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num  -87.6 -87.7 -87.7 -87.7 -87.6 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(may_2023)
## 'data.frame':    604827 obs. of  13 variables:
##  $ ride_id           : chr  "0D9FA920C3062031" "92485E5FB5888ACD" "FB144B3FC8300187" "DDEB93BC2CE9AA77" ...
##  $ rideable_type     : chr  "electric_bike" "electric_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : chr  "2023-05-07 19:53:48" "2023-05-06 18:54:08" "2023-05-21 00:40:21" "2023-05-10 16:47:01" ...
##  $ ended_at          : chr  "2023-05-07 19:58:32" "2023-05-06 19:03:35" "2023-05-21 00:44:36" "2023-05-10 16:59:52" ...
##  $ start_station_name: chr  "Southport Ave & Belmont Ave" "Southport Ave & Belmont Ave" "Halsted St & 21st St" "Carpenter St & Huron St" ...
##  $ start_station_id  : chr  "13229" "13229" "13162" "13196" ...
##  $ end_station_name  : chr  "" "" "" "Damen Ave & Cortland St" ...
##  $ end_station_id    : chr  "" "" "" "13133" ...
##  $ start_lat         : num  41.9 41.9 41.9 41.9 42 ...
##  $ start_lng         : num  -87.7 -87.7 -87.6 -87.7 -87.7 ...
##  $ end_lat           : num  41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num  -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(june_2023)
## 'data.frame':    719618 obs. of  13 variables:
##  $ ride_id           : chr  "6F1682AC40EB6F71" "622A1686D64948EB" "3C88859D926253B4" "EAD8A5E0259DEC88" ...
##  $ rideable_type     : chr  "electric_bike" "electric_bike" "electric_bike" "electric_bike" ...
##  $ started_at        : chr  "2023-06-05 13:34:12" "2023-06-05 01:30:22" "2023-06-20 18:15:49" "2023-06-19 14:56:00" ...
##  $ ended_at          : chr  "2023-06-05 14:31:56" "2023-06-05 01:33:06" "2023-06-20 18:32:05" "2023-06-19 15:00:35" ...
##  $ start_station_name: chr  "" "" "" "" ...
##  $ start_station_id  : chr  "" "" "" "" ...
##  $ end_station_name  : chr  "" "" "" "" ...
##  $ end_station_id    : chr  "" "" "" "" ...
##  $ start_lat         : num  41.9 41.9 42 42 42 ...
##  $ start_lng         : num  -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ end_lat           : num  41.9 41.9 41.9 42 42 ...
##  $ end_lng           : num  -87.7 -87.7 -87.6 -87.7 -87.7 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(july_2023)
## 'data.frame':    767650 obs. of  13 variables:
##  $ ride_id           : chr  "9340B064F0AEE130" "D1460EE3CE0D8AF8" "DF41BE31B895A25E" "9624A293749EF703" ...
##  $ rideable_type     : chr  "electric_bike" "classic_bike" "classic_bike" "electric_bike" ...
##  $ started_at        : chr  "2023-07-23 20:06:14" "2023-07-23 17:05:07" "2023-07-23 10:14:53" "2023-07-21 08:27:44" ...
##  $ ended_at          : chr  "2023-07-23 20:22:44" "2023-07-23 17:18:37" "2023-07-23 10:24:29" "2023-07-21 08:32:40" ...
##  $ start_station_name: chr  "Kedzie Ave & 110th St" "Western Ave & Walton St" "Western Ave & Walton St" "Racine Ave & Randolph St" ...
##  $ start_station_id  : chr  "20204" "KA1504000103" "KA1504000103" "13155" ...
##  $ end_station_name  : chr  "Public Rack - Racine Ave & 109th Pl" "Milwaukee Ave & Grand Ave" "Damen Ave & Pierce Ave" "Clinton St & Madison St" ...
##  $ end_station_id    : chr  "877" "13033" "TA1305000041" "TA1305000032" ...
##  $ start_lat         : num  41.7 41.9 41.9 41.9 42 ...
##  $ start_lng         : num  -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ end_lat           : num  41.7 41.9 41.9 41.9 42 ...
##  $ end_lng           : num  -87.7 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(august_2023)
## 'data.frame':    771693 obs. of  13 variables:
##  $ ride_id           : chr  "903C30C2D810A53B" "F2FB18A98E110A2B" "D0DEC7C94E4663DA" "E0DDDC5F84747ED9" ...
##  $ rideable_type     : chr  "electric_bike" "electric_bike" "electric_bike" "electric_bike" ...
##  $ started_at        : chr  "2023-08-19 15:41:53" "2023-08-18 15:30:18" "2023-08-30 16:15:08" "2023-08-30 16:24:07" ...
##  $ ended_at          : chr  "2023-08-19 15:53:36" "2023-08-18 15:45:25" "2023-08-30 16:27:37" "2023-08-30 16:33:34" ...
##  $ start_station_name: chr  "LaSalle St & Illinois St" "Clark St & Randolph St" "Clark St & Randolph St" "Wells St & Elm St" ...
##  $ start_station_id  : chr  "13430" "TA1305000030" "TA1305000030" "KA1504000135" ...
##  $ end_station_name  : chr  "Clark St & Elm St" "" "" "" ...
##  $ end_station_id    : chr  "TA1307000039" "" "" "" ...
##  $ start_lat         : num  41.9 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num  -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ end_lat           : num  41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num  -87.6 -87.6 -87.6 -87.6 -87.7 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(september_2023)
## 'data.frame':    666371 obs. of  13 variables:
##  $ ride_id           : chr  "011C1903BF4E2E28" "87DB80E048A1BF9F" "7C2EB7AF669066E3" "57D197B010269CE3" ...
##  $ rideable_type     : chr  "classic_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : chr  "2023-09-23 00:27:50" "2023-09-02 09:26:43" "2023-09-25 18:30:11" "2023-09-13 15:30:49" ...
##  $ ended_at          : chr  "2023-09-23 00:33:27" "2023-09-02 09:38:19" "2023-09-25 18:41:39" "2023-09-13 15:39:18" ...
##  $ start_station_name: chr  "Halsted St & Wrightwood Ave" "Clark St & Drummond Pl" "Financial Pl & Ida B Wells Dr" "Clark St & Drummond Pl" ...
##  $ start_station_id  : chr  "TA1309000061" "TA1307000142" "SL-010" "TA1307000142" ...
##  $ end_station_name  : chr  "Sheffield Ave & Wellington Ave" "Racine Ave & Fullerton Ave" "Racine Ave & 15th St" "Racine Ave & Belmont Ave" ...
##  $ end_station_id    : chr  "TA1307000052" "TA1306000026" "13304" "TA1308000019" ...
##  $ start_lat         : num  41.9 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num  -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ end_lat           : num  41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num  -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ member_casual     : chr  "member" "member" "member" "member" ...
str(october_2023)
## 'data.frame':    537108 obs. of  13 variables:
##  $ ride_id           : chr  "3CB26DA7B86F34E7" "09950211363C6DEA" "A97914CD757A75F0" "1780A2A28E05BC38" ...
##  $ rideable_type     : chr  "electric_bike" "classic_bike" "classic_bike" "classic_bike" ...
##  $ started_at        : chr  "2023-10-02 18:49:43" "2023-10-14 20:35:28" "2023-10-01 11:54:35" "2023-10-09 17:14:39" ...
##  $ ended_at          : chr  "2023-10-02 18:59:51" "2023-10-14 20:46:18" "2023-10-01 12:12:53" "2023-10-09 17:24:16" ...
##  $ start_station_name: chr  "Ashland Ave & Blackhawk St" "Southport Ave & Clark St" "DuSable Lake Shore Dr & Monroe St" "Streeter Dr & Grand Ave" ...
##  $ start_station_id  : chr  "13224" "TA1308000047" "13300" "13022" ...
##  $ end_station_name  : chr  "Clark St & Schiller St" "Sheridan Rd & Lawrence Ave" "Clark St & Schiller St" "Michigan Ave & Oak St" ...
##  $ end_station_id    : chr  "TA1309000024" "TA1309000041" "TA1309000024" "13042" ...
##  $ start_lat         : num  41.9 42 41.9 41.9 41.9 ...
##  $ start_lng         : num  -87.7 -87.7 -87.6 -87.6 -87.7 ...
##  $ end_lat           : num  41.9 42 41.9 41.9 41.9 ...
##  $ end_lng           : num  -87.6 -87.7 -87.6 -87.6 -87.6 ...
##  $ member_casual     : chr  "casual" "casual" "member" "member" ...
compare_df_cols(january_2023,february_2023,march_2023,april_2023,
                may_2023,june_2023,july_2023,august_2023,
                september_2023,october_2023,return = "mismatch")
##  [1] column_name    january_2023   february_2023  march_2023     april_2023    
##  [6] may_2023       june_2023      july_2023      august_2023    september_2023
## [11] october_2023  
## <0 rows> (or 0-length row.names)

The function above confirms that there are no mismatched datatypes across all 10 of the data sets. I combined all 10 data sets into a single data frame by stacking them vertically.

Combine 10 dataset into one dataset

In this case, all variable types are the same and all the columns are named likewise in a logical way, so it’s not necessary to format the names. In this manner, we can proceed to combine all datasets in a single dataframe for the year 2023.

Note: Although there are null values for some station names, this data will not be used in this analysis.

totalyear_2023 <- bind_rows(january_2023,february_2023,march_2023,april_2023,
                            may_2023,june_2023,july_2023,august_2023,
                            september_2023,october_2023)
tibble(totalyear_2023)
## # A tibble: 5,133,281 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 F96D5A… electric_bike 2023-01-2… 2023-01… Lincoln Ave & Ful… TA1309000058    
##  2 13CB7E… classic_bike  2023-01-1… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  3 BD88A2… electric_bike 2023-01-0… 2023-01… Western Ave & Lun… RP-005          
##  4 C90792… classic_bike  2023-01-2… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  5 339701… classic_bike  2023-01-1… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  6 58E681… electric_bike 2023-01-3… 2023-01… Lakeview Ave & Fu… TA1309000019    
##  7 2F7194… electric_bike 2023-01-1… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  8 DB1CF8… classic_bike  2023-01-2… 2023-01… Kimbark Ave & 53r… TA1309000037    
##  9 34EAB9… electric_bike 2023-01-2… 2023-01… Kimbark Ave & 53r… TA1309000037    
## 10 BC8AB1… classic_bike  2023-01-0… 2023-01… Kimbark Ave & 53r… TA1309000037    
## # ℹ 5,133,271 more rows
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>

tail() function is used to verify the last 10 records from the combined dataset

as_tibble(tail(totalyear_2023,10))
## # A tibble: 10 × 13
##    ride_id rideable_type started_at ended_at start_station_name start_station_id
##    <chr>   <chr>         <chr>      <chr>    <chr>              <chr>           
##  1 33CDD2… classic_bike  2023-10-1… 2023-10… Kedzie Ave & Milw… 13085           
##  2 0BA056… classic_bike  2023-10-1… 2023-10… Kedzie Ave & Milw… 13085           
##  3 E35EC7… classic_bike  2023-10-2… 2023-10… Kedzie Ave & Milw… 13085           
##  4 FAF571… classic_bike  2023-10-0… 2023-10… Kedzie Ave & Milw… 13085           
##  5 817A0A… classic_bike  2023-10-2… 2023-10… Kedzie Ave & Milw… 13085           
##  6 62A15B… classic_bike  2023-10-0… 2023-10… Kedzie Ave & Milw… 13085           
##  7 3ADAD7… classic_bike  2023-10-1… 2023-10… Kedzie Ave & Milw… 13085           
##  8 3C28D5… electric_bike 2023-10-0… 2023-10… Elizabeth St & Ra… 23001           
##  9 8167A1… electric_bike 2023-10-1… 2023-10… Kedzie Ave & Milw… 13085           
## 10 4890C7… classic_bike  2023-10-2… 2023-10… Kedzie Ave & Milw… 13085           
## # ℹ 7 more variables: end_station_name <chr>, end_station_id <chr>,
## #   start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## #   member_casual <chr>
str(totalyear_2023)
## 'data.frame':    5133281 obs. of  13 variables:
##  $ ride_id           : chr  "F96D5A74A3E41399" "13CB7EB698CEDB88" "BD88A2E670661CE5" "C90792D034FED968" ...
##  $ rideable_type     : chr  "electric_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : chr  "2023-01-21 20:05:42" "2023-01-10 15:37:36" "2023-01-02 07:51:57" "2023-01-22 10:52:58" ...
##  $ ended_at          : chr  "2023-01-21 20:16:33" "2023-01-10 15:46:05" "2023-01-02 08:05:11" "2023-01-22 11:01:44" ...
##  $ start_station_name: chr  "Lincoln Ave & Fullerton Ave" "Kimbark Ave & 53rd St" "Western Ave & Lunt Ave" "Kimbark Ave & 53rd St" ...
##  $ start_station_id  : chr  "TA1309000058" "TA1309000037" "RP-005" "TA1309000037" ...
##  $ end_station_name  : chr  "Hampden Ct & Diversey Ave" "Greenwood Ave & 47th St" "Valli Produce - Evanston Plaza" "Greenwood Ave & 47th St" ...
##  $ end_station_id    : chr  "202480.0" "TA1308000002" "599" "TA1308000002" ...
##  $ start_lat         : num  41.9 41.8 42 41.8 41.8 ...
##  $ start_lng         : num  -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ end_lat           : num  41.9 41.8 42 41.8 41.8 ...
##  $ end_lng           : num  -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr  "member" "member" "casual" "member" ...
skim_without_charts(totalyear_2023)
Data summary
Name totalyear_2023
Number of rows 5133281
Number of columns 13
_______________________
Column type frequency:
character 9
numeric 4
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
ride_id 0 1 16 16 0 5133281 0
rideable_type 0 1 11 13 0 3 0
started_at 0 1 19 19 0 4294414 0
ended_at 0 1 19 19 0 4305394 0
start_station_name 0 1 0 64 785003 1568 0
start_station_id 0 1 0 35 785135 1490 0
end_station_name 0 1 0 64 833375 1574 0
end_station_id 0 1 0 35 833516 1495 0
member_casual 0 1 6 6 0 2 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100
start_lat 0 1 41.90 0.04 41.63 41.88 41.90 41.93 42.07
start_lng 0 1 -87.65 0.03 -87.94 -87.66 -87.64 -87.63 -87.46
end_lat 6397 1 41.90 0.06 0.00 41.88 41.90 41.93 42.18
end_lng 6397 1 -87.65 0.07 -88.16 -87.66 -87.64 -87.63 0.00
dim(totalyear_2023)
## [1] 5133281      13

Cleaning the data

In practical situations, I typically consult with a senior colleague or one of the main project stakeholders to clarify the specific data cleaning procedures permissible for the project. For instance, I seek guidance on how to handle null values and whether it’s acceptable to completely remove any data from the original “totalyear_2023” data frame. I execute all data cleaning, including deletion operations, while ensuring the preservation of the original “totalyear_2023” data frame’s integrity.

totalyear_2023 <- drop_na(totalyear_2023)

Adding new column

We will use the new dataframe to extract the date, including month, day of the week, date number and year, for each bike ride.

This line should be modified to convert the data in column “started_at” to a “Date” type variable.

totalyear_2023$date <- as.Date(totalyear_2023$started_at)

totalyear_2023$month <- format(as.Date(totalyear_2023$date, "%Y-%m-%d"), "%m")
totalyear_2023$day <- format(as.Date(totalyear_2023$date, "%Y-%m-%d"), "%d")
totalyear_2023$year <- format(as.Date(totalyear_2023$date, "%Y-%m-%d"), "%Y")
totalyear_2023$day_of_week <- format(as.Date(totalyear_2023$date, "%Y-%m-%d"), "%A")

Subsequently, we will determine the duration of each bike ride by subtracting the “time when the ride ended” from the “time when the ride started.” The calculation will be expressed in minutes as the unit of measure. Additionally, we will filter out negative values and convert the results to “numeric” to facilitate accurate analysis.

totalyear_2023$ride_length <- difftime(totalyear_2023$ended_at, totalyear_2023$started_at, units= "mins")

totalyear_2023_v2 <- totalyear_2023[totalyear_2023$ride_length > 0, ]

totalyear_2023_v2 <- totalyear_2023_v2 %>% 
  mutate(ride_length =as.numeric(ride_length))

head(totalyear_2023_v2)
##            ride_id rideable_type          started_at            ended_at
## 1 F96D5A74A3E41399 electric_bike 2023-01-21 20:05:42 2023-01-21 20:16:33
## 2 13CB7EB698CEDB88  classic_bike 2023-01-10 15:37:36 2023-01-10 15:46:05
## 3 BD88A2E670661CE5 electric_bike 2023-01-02 07:51:57 2023-01-02 08:05:11
## 4 C90792D034FED968  classic_bike 2023-01-22 10:52:58 2023-01-22 11:01:44
## 5 3397017529188E8A  classic_bike 2023-01-12 13:58:01 2023-01-12 14:13:20
## 6 58E68156DAE3E311 electric_bike 2023-01-31 07:18:03 2023-01-31 07:21:16
##              start_station_name start_station_id               end_station_name
## 1   Lincoln Ave & Fullerton Ave     TA1309000058      Hampden Ct & Diversey Ave
## 2         Kimbark Ave & 53rd St     TA1309000037        Greenwood Ave & 47th St
## 3        Western Ave & Lunt Ave           RP-005 Valli Produce - Evanston Plaza
## 4         Kimbark Ave & 53rd St     TA1309000037        Greenwood Ave & 47th St
## 5         Kimbark Ave & 53rd St     TA1309000037        Greenwood Ave & 47th St
## 6 Lakeview Ave & Fullerton Pkwy     TA1309000019      Hampden Ct & Diversey Ave
##   end_station_id start_lat start_lng  end_lat   end_lng member_casual
## 1       202480.0  41.92407 -87.64628 41.93000 -87.64000        member
## 2   TA1308000002  41.79957 -87.59475 41.80983 -87.59938        member
## 3            599  42.00857 -87.69048 42.03974 -87.69941        casual
## 4   TA1308000002  41.79957 -87.59475 41.80983 -87.59938        member
## 5   TA1308000002  41.79957 -87.59475 41.80983 -87.59938        member
## 6       202480.0  41.92607 -87.63886 41.93000 -87.64000        member
##         date month day year day_of_week ride_length
## 1 2023-01-21    01  21 2023    Saturday   10.850000
## 2 2023-01-10    01  10 2023     Tuesday    8.483333
## 3 2023-01-02    01  02 2023      Monday   13.233333
## 4 2023-01-22    01  22 2023      Sunday    8.766667
## 5 2023-01-12    01  12 2023    Thursday   15.316667
## 6 2023-01-31    01  31 2023     Tuesday    3.216667

In the following table, you will find a comprehensive summary of all bike rides. This summary provides insights into the total ride count, along with the minimun, maximum, mean and median durations of the bike rides.

global_ride_summary<- totalyear_2023_v2 %>% 
  summarize(
    customer_type ="TotalRides",
    number_of_rides = n_distinct (ride_id),
    min_ride_time = min (ride_length),
    max_ride_time = max(ride_length),
    mean_ride_time = mean(ride_length),
    median_ride_time = median(ride_length)
   )

View(global_ride_summary)

ANALYZE

Analyzing the data to find patterns, relationships and trends. Rstudio was used for the data analysis phase of this project.

For the “Members” and “Casuals” customer types, we should separate the data into two dataframes. This will make managing these groups easier.

casuals_df <- totalyear_2023_v2 %>% 
  filter(member_casual=="casual")

head(casuals_df)
##            ride_id rideable_type          started_at            ended_at
## 1 BD88A2E670661CE5 electric_bike 2023-01-02 07:51:57 2023-01-02 08:05:11
## 2 9DC70E5EE9D6A93F electric_bike 2023-01-03 20:25:53 2023-01-03 20:35:50
## 3 689D537E5D034DA8 electric_bike 2023-01-05 17:28:08 2023-01-05 17:43:24
## 4 A5CBC7142CA8FAD8  classic_bike 2023-01-02 12:45:48 2023-01-02 12:53:06
## 5 2B8E0781ED90C27C electric_bike 2023-01-11 17:03:25 2023-01-11 17:13:34
## 6 400D3C150A972867 electric_bike 2023-01-24 17:53:39 2023-01-24 17:58:58
##              start_station_name start_station_id               end_station_name
## 1        Western Ave & Lunt Ave           RP-005 Valli Produce - Evanston Plaza
## 2       Broadway & Waveland Ave            13325      Hampden Ct & Diversey Ave
## 3        Western Ave & Lunt Ave           RP-005 Valli Produce - Evanston Plaza
## 4         Clark St & Berwyn Ave     KA1504000146         Clark St & Elmdale Ave
## 5 Avondale Ave & Irving Park Rd            15624  Campbell Ave & Irving Park Rd
## 6       Clark St & Columbia Ave           RP-008         Clark St & Elmdale Ave
##   end_station_id start_lat start_lng  end_lat   end_lng member_casual
## 1            599  42.00857 -87.69048 42.03974 -87.69941        casual
## 2       202480.0  41.94911 -87.64863 41.93000 -87.64000        casual
## 3            599  42.00861 -87.69052 42.03974 -87.69941        casual
## 4   KA1504000148  41.97803 -87.66856 41.99086 -87.66972        casual
## 5            439  41.95318 -87.73195 41.95000 -87.69000        casual
## 6   KA1504000148  42.00446 -87.67238 41.99086 -87.66972        casual
##         date month day year day_of_week ride_length
## 1 2023-01-02    01  02 2023      Monday   13.233333
## 2 2023-01-03    01  03 2023     Tuesday    9.950000
## 3 2023-01-05    01  05 2023    Thursday   15.266667
## 4 2023-01-02    01  02 2023      Monday    7.300000
## 5 2023-01-11    01  11 2023   Wednesday   10.150000
## 6 2023-01-24    01  24 2023     Tuesday    5.316667
members_df <- totalyear_2023_v2 %>% 
  filter(member_casual=="member")

head(members_df)
##            ride_id rideable_type          started_at            ended_at
## 1 F96D5A74A3E41399 electric_bike 2023-01-21 20:05:42 2023-01-21 20:16:33
## 2 13CB7EB698CEDB88  classic_bike 2023-01-10 15:37:36 2023-01-10 15:46:05
## 3 C90792D034FED968  classic_bike 2023-01-22 10:52:58 2023-01-22 11:01:44
## 4 3397017529188E8A  classic_bike 2023-01-12 13:58:01 2023-01-12 14:13:20
## 5 58E68156DAE3E311 electric_bike 2023-01-31 07:18:03 2023-01-31 07:21:16
## 6 2F7194B6012A98D4 electric_bike 2023-01-15 21:18:36 2023-01-15 21:32:36
##              start_station_name start_station_id          end_station_name
## 1   Lincoln Ave & Fullerton Ave     TA1309000058 Hampden Ct & Diversey Ave
## 2         Kimbark Ave & 53rd St     TA1309000037   Greenwood Ave & 47th St
## 3         Kimbark Ave & 53rd St     TA1309000037   Greenwood Ave & 47th St
## 4         Kimbark Ave & 53rd St     TA1309000037   Greenwood Ave & 47th St
## 5 Lakeview Ave & Fullerton Pkwy     TA1309000019 Hampden Ct & Diversey Ave
## 6         Kimbark Ave & 53rd St     TA1309000037   Greenwood Ave & 47th St
##   end_station_id start_lat start_lng  end_lat   end_lng member_casual
## 1       202480.0  41.92407 -87.64628 41.93000 -87.64000        member
## 2   TA1308000002  41.79957 -87.59475 41.80983 -87.59938        member
## 3   TA1308000002  41.79957 -87.59475 41.80983 -87.59938        member
## 4   TA1308000002  41.79957 -87.59475 41.80983 -87.59938        member
## 5       202480.0  41.92607 -87.63886 41.93000 -87.64000        member
## 6   TA1308000002  41.79955 -87.59462 41.80983 -87.59938        member
##         date month day year day_of_week ride_length
## 1 2023-01-21    01  21 2023    Saturday   10.850000
## 2 2023-01-10    01  10 2023     Tuesday    8.483333
## 3 2023-01-22    01  22 2023      Sunday    8.766667
## 4 2023-01-12    01  12 2023    Thursday   15.316667
## 5 2023-01-31    01  31 2023     Tuesday    3.216667
## 6 2023-01-15    01  15 2023      Sunday   14.000000

Let’s create a single table that includes the global results we previously calculated.

casuals_ride_summary <- casuals_df %>% 
  summarize(
    customer_type = "Casuals",
    number_of_rides = n_distinct (ride_id),
    min_ride_time = min (ride_length),
    max_ride_time = max(ride_length),
    mean_ride_time = mean(ride_length),
    median_ride_time = median(ride_length)
   )
members_ride_summary <- members_df %>% 
  summarize(
    customer_type = "Members",
    number_of_rides = n_distinct (ride_id),
    min_ride_time = min (ride_length),
    max_ride_time = max(ride_length),
    mean_ride_time = mean(ride_length),
    median_ride_time = median(ride_length)
   )
total_summary <- bind_rows (casuals_ride_summary, members_ride_summary, 
                            global_ride_summary)

View(total_summary)

The mean time for bike rides is significantly higher for casual customers than for members. We’ll examine ride lengths for both types of customers at different time scales - yearly, monthly and daily - for a more detailed analysis.

Monthly and Days of the Week Data Management

It is necessary to sort the data and compute the number of rides, as well as the new averages for the length of bike rides.

Analysis: Mean time of ride per day of the week, for each group (casuals vs members)

days_order <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
casuals_data_per_day <- casuals_df %>%
  group_by(day_of_week) %>% 
  summarise (
    customer_type = "Casuals",
    number_of_rides = n_distinct (ride_id),
    mean_ride_time = mean(ride_length)
  ) %>% 
  arrange(match(day_of_week, days_order))
members_data_per_day <- members_df %>%
  group_by(day_of_week) %>% 
  summarise (
    customer_type = "Members",
    number_of_rides = n_distinct (ride_id),
    mean_ride_time = mean(ride_length)
  ) %>% 
  arrange(match(day_of_week, days_order))
days_rides_summary <- bind_rows (casuals_data_per_day, members_data_per_day) 

View(days_rides_summary)

Analysis: Mean time of ride per month, for each group (casuals vs members) Note: months must be renamed so they can appear as strings and not numbers

casuals_data_per_month <- casuals_df %>%
  group_by(month) %>% 
  summarise (
    customer_type = "Casuals",
    number_of_rides = n_distinct (ride_id),
    mean_ride_time = mean(ride_length)
  ) %>% 
  mutate(month = case_when(
    month == "01" ~ "January",
    month == "02" ~ "February",
    month == "03" ~ "March",
    month == "04" ~ "April",
    month == "05" ~ "May",
    month == "06" ~ "June",
    month == "07" ~ "July",
    month == "08" ~ "August",
    month == "09" ~ "September",
    month == "10" ~ "October",
    month == "11" ~ "November",
    month == "12" ~ "December",
  ))
members_data_per_month <- members_df %>%
  group_by(month) %>% 
  summarise (
    customer_type = "Members",
    number_of_rides = n_distinct (ride_id),
    mean_ride_time = mean(ride_length)
  ) %>% 
  mutate(month = case_when(
    month == "01" ~ "January",
    month == "02" ~ "February",
    month == "03" ~ "March",
    month == "04" ~ "April",
    month == "05" ~ "May",
    month == "06" ~ "June",
    month == "07" ~ "July",
    month == "08" ~ "August",
    month == "09" ~ "September",
    month == "10" ~ "October",
    month == "11" ~ "November",
    month == "12" ~ "December",
  ))
months_rides_summary <- bind_rows(casuals_data_per_month, members_data_per_month)

View(months_rides_summary)
color_palette <- c("#00aedb", "#f37735", "#007b7b")
ggplot(data = total_summary) +
  geom_col(mapping = aes(x = customer_type, y = number_of_rides, fill = customer_type))+
  scale_y_continuous(breaks = seq(0, max(total_summary$number_of_rides), by = 1000000),
                     labels = scales::label_number(suffix = "M", scale = 1e-6, big.mark = ".", decimal.mark = ",")) +
  theme_minimal() +
  theme(axis.text.x =element_text(size=14)) +
  theme(axis.text.y =element_text(size=14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)), axis.title.x = element_text(margin= margin(t=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(title= "Number of Rides per Type of Customer in 23'",
       x = "Types of Customers", y = "Number of Rides (Millions)", fill=NULL) +
  theme(plot.title=element_text(size= 22)) +
  scale_fill_manual(values= color_palette) +
  theme(legend.text = element_text(size = 15))

rides_percentages <- total_summary %>% 
  filter(customer_type== "Casuals" | customer_type =="Members" ) %>% 
  mutate(percentage= ((number_of_rides / 5133281)*100) /100)

ggplot(rides_percentages, aes(x="", y=percentage, fill=customer_type)) +
  geom_bar(stat="identity", width=1, color="white") +
  coord_polar("y", start=0)+
  theme_void() +
  labs(title="Proportion of Customers in 2023",
       fill=NULL) +
  geom_text(aes(label=scales::percent(percentage)), position=position_stack(vjust=0.5), size=10) +
  scale_fill_manual(values= color_palette)+
  theme(plot.title = element_text(size = 22)) +
  theme(legend.text = element_text(size = 14))

totalyear_2023_v2 %>%
  group_by(start_station_name, member_casual) %>%
  summarise(number_of_trips = n()) %>%
  arrange(desc(number_of_trips)) %>%
  filter(member_casual == "casual", number_of_trips >= 11300) %>%
  select(start_station_name, number_of_trips) %>%
  ggplot(aes(x = start_station_name, y = number_of_trips)) +
  geom_col(fill = "#00aedb") +
  coord_flip() +
  theme_minimal(base_size = 20) +
  theme(axis.text.x =element_text(size=14)) +
  theme(axis.text.y =element_text(size=14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)), axis.title.x = element_text(margin= margin(t=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(
    title = "Top 10 most popular start stations for casual riders",
    x = "Start station name",
    y = "Number of trips"
  ) +
  scale_y_continuous(labels = scales::comma_format(scale = 1E-1)) +
  theme(plot.title = element_text(size = 22, hjust = 1.0)) +
  theme(legend.text = element_text(size = 14))
## `summarise()` has grouped output by 'start_station_name'. You can override
## using the `.groups` argument.

totalyear_2023_v2 %>%
  group_by(end_station_name, member_casual) %>%
  summarise(number_of_trips = n()) %>%
  arrange(desc(number_of_trips)) %>%
  filter(member_casual == "casual", number_of_trips >= 11300) %>%
  select(end_station_name, number_of_trips) %>%
  ggplot(aes(x = end_station_name, y = number_of_trips)) +
  geom_col(fill = "#00aedb") +
  coord_flip() +
  theme_minimal(base_size = 20) +
  theme(axis.text.x =element_text(size=14)) +
  theme(axis.text.y =element_text(size=14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)), axis.title.x = element_text(margin= margin(t=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(
    title = "Top 10 most popular end stations for casual riders",
    x = "End station name",
    y = "Number of trips"
  ) +
  scale_y_continuous(labels = scales::comma_format(scale = 1E-1)) +
  theme(plot.title = element_text(size = 22, hjust = 1.0)) +
  theme(legend.text = element_text(size = 14))
## `summarise()` has grouped output by 'end_station_name'. You can override using
## the `.groups` argument.

totalyear_2023_v2 %>%
  group_by(start_station_name, member_casual) %>%
  summarise(number_of_trips = n()) %>%
  arrange(desc(number_of_trips)) %>%
  filter(member_casual == "member", number_of_trips >= 16000) %>%
  select(start_station_name, number_of_trips) %>%
  ggplot(aes(x = start_station_name, y = number_of_trips)) +
  geom_col(fill = "#f37735") +
  coord_flip() +
  theme_minimal(base_size = 35) +
  theme(axis.text.x =element_text(size=14)) +
  theme(axis.text.y =element_text(size=14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)), axis.title.x = element_text(margin= margin(t=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(
    title = "Top 10 most popular start stations for member riders",
    x = "Start station name",
    y = "Number of trips"
  ) +
  scale_y_continuous(labels = scales::comma_format(scale = 1E-1)) +
  theme(plot.title = element_text(size = 20, hjust = 1.0)) +
  theme(legend.text = element_text(size = 14))
## `summarise()` has grouped output by 'start_station_name'. You can override
## using the `.groups` argument.

totalyear_2023_v2 %>%
  group_by(end_station_name, member_casual) %>%
  summarise(number_of_trips = n()) %>%
  arrange(desc(number_of_trips)) %>%
  filter(member_casual == "member", number_of_trips >= 16000) %>%
  select(end_station_name, number_of_trips) %>%
  ggplot(aes(x = end_station_name, y = number_of_trips)) +
  geom_col(fill = "#f37735") +
  coord_flip() +
  theme_minimal(base_size = 38) +
  theme(axis.text.x =element_text(size=14)) +
  theme(axis.text.y =element_text(size=14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)), axis.title.x = element_text(margin= margin(t=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(
    title = "Top 10 most popular start stations for member riders",
    x = "End station name",
    y = "Number of trips"
  ) +
  scale_y_continuous(labels = scales::comma_format(scale = 1E-1)) +
  theme(plot.title = element_text(size = 20, hjust = 0.95)) +
  theme(legend.text = element_text(size = 14))
## `summarise()` has grouped output by 'end_station_name'. You can override using
## the `.groups` argument.

mean_ride_time_2022 <- total_summary %>% 
  filter(customer_type== "Casuals" | customer_type =="Members") %>% 
  select (customer_type, mean_ride_time)

ggplot(data=mean_ride_time_2022) +
  geom_col(mapping=aes(x=customer_type, y=mean_ride_time, fill=customer_type)) +
  theme_minimal() +
  theme(axis.text.x =element_text(size=14)) +
  theme(axis.text.y =element_text(size=14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)), axis.title.x = element_text(margin= margin(t=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(title= "Average Ride Time per Type of Customer in 23'",
       x = "Types of Customers", y = "Average Ride Time (Minutes)", fill=NULL)+
  theme(plot.title=element_text(size= 21)) +
  scale_fill_manual(values= color_palette) +
  theme(legend.text = element_text(size = 15))

First we need to reorder the months so they are displayed in order, and then we create the chart

months_order <- c("January", "February", "March", "April", "May", "June",
                  "July", "August", "September", "October", "November", "December")

months_rides_summary$month <- factor(months_rides_summary$month, levels = months_order)
ggplot(data = months_rides_summary) +
  geom_point(mapping = aes(x = month, y = mean_ride_time, color = customer_type), size = 5) +
  geom_smooth(mapping = aes(x = month, y = mean_ride_time, color = customer_type, group = customer_type),
              formula = y ~ x, method = "loess", se = FALSE, linewidth = 1) + 
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1, size= 14)) +
  theme(axis.text.y= element_text(size= 14)) +
  theme(axis.title.y = element_text(margin = margin(r = 10))) +
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(title = "Average Ride Time per Month in 2023",
       x = "Month", y = "Average Ride Time (Minutes)", color = NULL) +
  theme(plot.title = element_text(size = 22)) +
  scale_y_continuous(limits = c(0, 35), breaks = seq(0, 35, by = 10)) +
  scale_color_manual(values = color_palette) +
  theme(legend.text = element_text(size = 15))

First we need to reorder the weekdays so they are displayed in order, and then we create the chart

Note: days_order was already defined

ggplot(data = days_rides_summary) +
  geom_point(mapping = aes(x = day_of_week, y = mean_ride_time, color = customer_type), size = 5) +
  geom_smooth(mapping = aes(x = day_of_week, y = mean_ride_time, color = customer_type, group = customer_type),
              formula = y ~ x, method = "loess", se = FALSE, linewidth = 1) +
  theme_minimal() +
  theme(axis.text.x= element_text(angle = 45, hjust=1, size=14)) +
  theme (axis.text.y = element_text(size = 14)) +
  theme(axis.title.y= element_text(margin= margin(r=10)))+
  theme(axis.title.x= element_text(size=18), axis.title.y= element_text(size=18)) +
  labs(title= "Average Ride Time per Day of the Week in 23'",
       x = "Day of the Week", y = "Average Ride Time (Minutes)", color=NULL) +
  theme(plot.title=element_text(size= 21)) +
  scale_y_continuous(limits=c(0,40), breaks= seq(0,40, by=10)) +
  scale_color_manual(values= color_palette) +
  theme(legend.text = element_text(size = 15))

SHARE

Findings are shared and communicated to the relevant stakeholders.

ACT

After the data has been processed, analyzed and insights have been shared, the final phase is to recommend a plan of action for the bikeshare company in line with their business task and objectives. My recommendations are: ## Recommendation 1: Targeted Promotions Identify specific promotions or incentives that would appeal to casual riders and encourage them to become annual members. This could include discounted membership rates, referral programs, or exclusive offers.

Recommendation 2: Improve User Experience

Enhance the user experience for casual riders, addressing any pain points or barriers that may prevent them from becoming annual members. This could involve improving the bike rental process, introducing user-friendly features, or streamlining the membership sign-up process.

Recommendation 3: Digital Media Campaign

Utilize digital media channels to promote Cyclistic memberships to casual riders. Craft engaging and targeted digital campaigns that showcase the benefits of annual membership, leveraging social media, email, and other online platforms.

By implementing these recommendations, Cyclistic aims to maximize the conversion of casual riders into annual members, contributing to the company’s overall growth and success.