Divvy Trips Bike Share Analysis
Project links
Skills
About this project
Divvy Trips Bike Share Analysis
This project delves into understanding the usage patterns of annual members and casual riders in a bike share company, aiming to tailor a marketing strategy towards converting casual riders into annual members. Financial analyses have highlighted the significantly higher profitability of annual memberships compared to casual ones.
Data Preparation and Analysis:
The analysis focuses on historical trip data spanning April 2019 to March 2020, sourced from [Divvy Trip Data](https://divvy-tripdata.s3.amazonaws.com/index.html). Trip duration and day of the week were processed using Excel formulas to facilitate analysis. Trip data was filtered to exclude invalid trip lengths and ensure accuracy.
Excel Processing:
Trip data was processed in Excel, with each file saved individually and columns added for trip length and day of the week. Pivot tables were utilized to analyze ride counts and average ride lengths by member type and day of the week. Bar graph visulizations provide insights into usage patterns.


Insights from Excel Analysis:
Comparative analysis revealed that annual members predominantly ride on weekdays, while casual riders prefer weekends. Moreover, casual riders tend to have longer average ride lengths compared to annual members on weekdays.
Actionable Recommendations:
Based on the analysis, a marketing strategy targeting casual riders with ride lengths between 10-20 minutes on weekdays is recommended to incentivize annual membership conversions. Strategies such as offering free trials or discounts on annual memberships could be effective in this regard.
SQL BigQuery Processing and Analysing:
To delve deeper into the data, SQL analysis was performed using BigQuery. Large datasets were cleaned and modified, with unnecessary data removed from the trips table to create two new tables: customers and stations. This relational database will facilitate further analysis and modifications.
CREATE TABLE `skillful-hope-402814.divvy_trip_data.apr19-mar20` as
(SELECT CAST(ride_id AS STRING) AS ride_id, member_casual, ride_length, week_day
FROM `skillful-hope-402814.divvy_trip_data.2019-Q2`
UNION ALL
SELECT CAST(ride_id AS STRING) AS ride_id, member_casual, ride_length, week_day
FROM `skillful-hope-402814.divvy_trip_data.2019-Q3`
UNION ALL
SELECT CAST(ride_id AS STRING) AS ride_id, member_casual, ride_length, week_day
FROM `skillful-hope-402814.divvy_trip_data.2019-Q4`
UNION ALL
SELECT ride_id, member_casual, ride_length, week_day
FROM `skillful-hope-402814.divvy_trip_data.2020-Q1`)
##Now there is a new table of a full year for the analysis, I've checked for different names inputs to memeber_casual column:
SELECT member_casual, count(ride_id)
FROM `skillful-hope-402814.divvy_trip_data.apr19-mar20`
GROUP BY member_casual
## Subscriber needs to be change to member, and Customer to casual and run again the Query.
UPDATE
`skillful-hope-402814.divvy_trip_data.apr19-mar20`
SET
member_casual = "casual"
WHERE
member_casual = 'Customer'
UPDATE
`skillful-hope-402814.divvy_trip_data.apr19-mar20`
SET
member_casual = "member"
WHERE
member_casual = 'Subscriber'
##Analyse in SQL:
##Get the amount of rides made by casual and members each week day.
SELECT week_day, countif(member_casual = 'member') as member, countif(member_casual = 'casual') AS casual
FROM `skillful-hope-402814.divvy_trip_data.apr19-mar20`
WHERE ride_length > 0
GROUP BY week_day
##Get the average length of rides made by casual and members each week day.
SELECT
week_day,
AVG(CASE WHEN member_casual = 'casual' THEN ride_length ELSE NULL END) AS casual,
AVG(CASE WHEN member_casual = 'member' THEN ride_length ELSE NULL END) AS member
FROM
`divvy_trip_data.apr19-mar20`
GROUP BY
week_day
ORDER BY
week_day;
R Programming:
R programming was employed to enhance the documented analysis, and visualizations were generated using R Studio. Insights from the R analysis complemented findings from Excel and SQL, providing a holistic understanding of usage patterns and member behaviors. Additionally, R facilitated the integration of analysis across different tools, depending on the company's data needs and requirements.
library(tidyverse) # To import and wrangle data
library(lubridate) # For date attributes
library(ggplot2) # For visualizations
setwd("C:/Users/gsara/OneDrive/Desktop/Data_Analysis/case_study_1/data") # Sets directory to upload files from
q2_2019 <- read_csv("Divvy_Trips_2019_Q2.csv") # Creates tables from data files
q3_2019 <- read_csv("Divvy_Trips_2019_Q3.csv")
q4_2019 <- read_csv("Divvy_Trips_2019_Q4.csv")
q1_2020 <- read_csv("Divvy_Trips_2020_Q1.csv")
# Changing column names to make them simmilar in all tables
(q4_2019 <- rename(q4_2019,ride_id = trip_id
,rideable_type = bikeid
,started_at = start_time
,ended_at = end_time
,start_station_name = from_station_name
,start_station_id = from_station_id
,end_station_name = to_station_name
,end_station_id = to_station_id
,member_casual = usertype))
(q3_2019 <- rename(q3_2019
,ride_id = trip_id
,rideable_type = bikeid
,started_at = start_time
,ended_at = end_time
,start_station_name = from_station_name
,start_station_id = from_station_id
,end_station_name = to_station_name
,end_station_id = to_station_id
,member_casual = usertype))
(q2_2019 <- rename(q2_2019
,ride_id = "01 - Rental Details Rental ID"
,rideable_type = "01 - Rental Details Bike ID"
,started_at = "01 - Rental Details Local Start Time"
,ended_at = "01 - Rental Details Local End Time"
,start_station_name = "03 - Rental Start Station Name"
,start_station_id = "03 - Rental Start Station ID"
,end_station_name = "02 - Rental End Station Name"
,end_station_id = "02 - Rental End Station ID"
,member_casual = "User Type"))
# Inspect the dataframes and look for inconguencies
str(q1_2020)
str(q4_2019)
str(q3_2019)
str(q2_2019)
# Convert ride_id and rideable_type to character so that they can stack correctly
q4_2019 <- mutate(q4_2019, ride_id = as.character(ride_id), rideable_type = as.character(rideable_type))
q3_2019 <- mutate(q3_2019, ride_id = as.character(ride_id), rideable_type = as.character(rideable_type))
q2_2019 <- mutate(q2_2019, ride_id = as.character(ride_id), rideable_type = as.character(rideable_type))
# Stack individual quarter's data frames into one big data frame
all_trips <- bind_rows(q2_2019, q3_2019, q4_2019, q1_2020)
# Remove lat, long, birthyear, and gender fields as this data was dropped beginning in 2020
all_trips <- all_trips %>% select(-c(start_lat, start_lng, end_lat, end_lng, birthyear, gender, "01 - Rental Details Duration In Seconds Uncapped", "05 - Member Details Member Birthday Year", "Member Gender", "tripduration"))
# Begin by seeing how many observations fall under each usertype
table(all_trips$member_casual)
# Reassign to the desired values (we will go with the current 2020 labels
all_trips <- all_trips %>%
mutate(member_casual = recode(member_casual
,"Subscriber" = "member"
,"Customer" = "casual"))
# Check to make sure the proper number of observations were reassigned
table(all_trips$member_casual)
# Add columns that list the date, month, day, and year of each ride
all_trips$date <- as.Date(all_trips$started_at) #The default format is yyyy-mm-dd
all_trips$month <- format(as.Date(all_trips$date), "%m")
all_trips$day <- format(as.Date(all_trips$date), "%d")
all_trips$year <- format(as.Date(all_trips$date), "%Y")
all_trips$day_of_week <- format(as.Date(all_trips$date), "%A")
# Add a "ride_length" calculation to all_trips (in seconds)
all_trips$ride_length <- difftime(all_trips$ended_at,all_trips$started_at)
# Convert "ride_length" from Factor to numeric so we can run calculations on the data
all_trips$ride_length <- as.numeric(as.character(all_trips$ride_length))
# Remove "bad" data
all_trips_v2 <- all_trips[!(all_trips$start_station_name == "HQ QR" | all_trips$ride_length<0),]
# Notice that the days of the week are out of order. Let's fix that. (My computer is in Spanish, so lables are in spanish)
all_trips_v2$day_of_week <- ordered(all_trips_v2$day_of_week, levels=c("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"))
# Now, let's run the average ride time by each day for members vs casual users
aggregate(all_trips_v2$ride_length ~ all_trips_v2$member_casual + all_trips_v2$day_of_week, FUN = mean)
# analyze ridership data by type and weekday
all_trips_v2 %>%
mutate(weekday = wday(started_at, label = TRUE)) %>% #creates weekday field using wday()
group_by(member_casual, weekday) %>% #groups by usertype and weekday
summarise(number_of_rides = n() #calculates the number of rides and average duration
,average_duration = mean(ride_length)) %>% # calculates the average duration
arrange(member_casual, weekday) # sorts
# Let's visualize the number of rides by rider type
all_trips_v2 %>%
mutate(weekday = wday(started_at, label = TRUE)) %>%
group_by(member_casual, weekday) %>%
summarise(number_of_rides = n()
,average_duration = mean(ride_length)) %>%
arrange(member_casual, weekday) %>%
ggplot(aes(x = weekday, y = number_of_rides, fill = member_casual)) +
geom_col(position = "dodge")
# Let's create a visualization for average duration
all_trips_v2 %>%
mutate(weekday = wday(started_at, label = TRUE)) %>%
group_by(member_casual, weekday) %>%
summarise(number_of_rides = n()
,average_duration = mean(ride_length)) %>%
arrange(member_casual, weekday) %>%
ggplot(aes(x = weekday, y = average_duration, fill = member_casual)) +
geom_col(position = "dodge")


This project showcases a multi-faceted approach to data analysis, leveraging Excel, SQL, and R programming to extract actionable insights and inform strategic decision-making in the bike share company's marketing efforts.