Cyclistic is a fictitious bike-share company based on real data, with bike stations positioned all over Chicago. As a junior data analyst, my role in this case study is to create the following deliverables, which happen to align with Google’s data analysis process:
In the following sections, I’ll document how I went about doing this in RStudio.
The question being asked in this situation is, “How do annual members and casual riders use Cyclistic differently?” The business task here is pretty clearly to find ways for marketing to influence casual riders to convert them into membership users. That means we’ve got stakeholders in marketing who will need the insights this data offers.
In this scenario, Cyclistic had multiple up-to-date datasets ready to use. I downloaded them, read them into RStudio, and started working on getting them to a useful state.
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'dplyr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ 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
november_2023 <- read.csv("202310-divvy-tripdata.csv")
as_tibble(november_2023)
## # A tibble: 537,113 × 13
## ride_id rideable_type started_at ended_at start_station_name start_station_id
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 444909… classic_bike 2023-10-0… 2023-10… Orleans St & Ches… 620
## 2 9CF060… electric_bike 2023-10-1… 2023-10… Desplaines St & K… TA1306000003
## 3 667F21… electric_bike 2023-10-1… 2023-10… Orleans St & Ches… 620
## 4 F92714… classic_bike 2023-10-2… 2023-10… Desplaines St & K… TA1306000003
## 5 5E34BA… classic_bike 2023-10-0… 2023-10… Desplaines St & K… TA1306000003
## 6 F7D742… electric_bike 2023-10-0… 2023-10… Orleans St & Ches… 620
## 7 870B2D… electric_bike 2023-10-3… 2023-10… Orleans St & Ches… 620
## 8 D9179D… classic_bike 2023-10-0… 2023-10… Desplaines St & K… TA1306000003
## 9 F8E131… classic_bike 2023-10-1… 2023-10… Calumet Ave & 18t… 13102
## 10 91938B… classic_bike 2023-10-1… 2023-10… Wolcott Ave & Pol… TA1309000064
## # ℹ 537,103 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>
Looking over the data, it’s clear that some of the columns are no longer useful for analysis, and others could become useful if transformed. First, I cleaned up the dataset by removing things we don’t need.
nov_23 <- subset(november_2023, select = -c(start_station_name, start_station_id, end_station_name, end_station_id, start_lat, start_lng, end_lat, end_lng))
as_tibble(nov_23)
## # A tibble: 537,113 × 5
## ride_id rideable_type started_at ended_at member_casual
## <chr> <chr> <chr> <chr> <chr>
## 1 4449097279F8BBE7 classic_bike 2023-10-08 10:36:26 2023-10-08 … member
## 2 9CF060543CA7B439 electric_bike 2023-10-11 17:23:59 2023-10-11 … member
## 3 667F21F4D6BDE69C electric_bike 2023-10-12 07:02:33 2023-10-12 … member
## 4 F92714CC6B019B96 classic_bike 2023-10-24 19:13:03 2023-10-24 … member
## 5 5E34BA5DE945A9CC classic_bike 2023-10-09 18:19:26 2023-10-09 … member
## 6 F7D7420AFAC53CD9 electric_bike 2023-10-04 17:10:59 2023-10-04 … member
## 7 870B2D4CD112D7B7 electric_bike 2023-10-31 17:32:20 2023-10-31 … member
## 8 D9179D36E32D456C classic_bike 2023-10-02 18:51:51 2023-10-02 … casual
## 9 F8E131281F722FEF classic_bike 2023-10-17 08:28:18 2023-10-17 … member
## 10 91938B71748FA405 classic_bike 2023-10-17 19:17:38 2023-10-17 … member
## # ℹ 537,103 more rows
Now we’re down to a measly 5 variables. No big deal, we’re about to get more. Normally, working with the started_at and ended_at columns would be really easy with lubridate, but they’re not formatted as POSIXlt vectors, so we need to do a little finagling first. lapply makes the functions apply to the whole column they’re referencing.
nov_23['start_sec'] <- lapply(nov_23["started_at"], function(x) as.numeric(strptime(x, "%Y-%m-%d %H:%M:%S")))
nov_23['end_sec'] <- lapply(nov_23["ended_at"], function(x) as.numeric(strptime(x, "%Y-%m-%d %H:%M:%S")))
Now that we’ve turned those dates into Unix timestamps, we can just subtract one from the other. This gives us the trip durations in seconds.
nov_23['duration_sec'] <- nov_23["end_sec"] - nov_23["start_sec"]
as_tibble(c(nov_23["start_sec"], nov_23["end_sec"], nov_23["duration_sec"]))
## # A tibble: 537,113 × 3
## start_sec end_sec duration_sec
## <dbl> <dbl> <dbl>
## 1 1696779386 1696780159 773
## 2 1697063039 1697063768 729
## 3 1697112153 1697112413 260
## 4 1698192783 1698193109 326
## 5 1696893566 1696894256 690
## 6 1696457459 1696458321 862
## 7 1698791540 1698792260 720
## 8 1696290711 1696291029 318
## 9 1697549298 1697550603 1305
## 10 1697588258 1697589143 885
## # ℹ 537,103 more rows
We want to glean some insights from the user activity divided by weekday as well, so in order to be able to use the started_at vector with certain useful lubridate commands, we need to reformat that column as POSIXlt.
nov_23['trip_date'] <- lapply(nov_23["started_at"], as.POSIXlt)
Now our new column trip_date, will be readable by wday, a lubridate command that transforms a YMD date format into a weekday output. The command wday only gives us the weekday’s number, so we then use the weekdays command to make another column that gives us those.
nov_23['day_of_week'] <- lapply(nov_23["trip_date"], function(x) wday(x, week_start = 1))
nov_23['day_name'] <- lapply(nov_23["trip_date"], function(x) weekdays(x, abbreviate = FALSE))
as_tibble(c(nov_23["trip_date"], nov_23["day_of_week"], nov_23["day_name"]))
## # A tibble: 537,113 × 3
## trip_date day_of_week day_name
## <dttm> <dbl> <chr>
## 1 2023-10-08 10:36:26 7 Sunday
## 2 2023-10-11 17:23:59 3 Wednesday
## 3 2023-10-12 07:02:33 4 Thursday
## 4 2023-10-24 19:13:03 2 Tuesday
## 5 2023-10-09 18:19:26 1 Monday
## 6 2023-10-04 17:10:59 3 Wednesday
## 7 2023-10-31 17:32:20 2 Tuesday
## 8 2023-10-02 18:51:51 1 Monday
## 9 2023-10-17 08:28:18 2 Tuesday
## 10 2023-10-17 19:17:38 2 Tuesday
## # ℹ 537,103 more rows
Now we’ve got 11 variables, and several of those are about to be useful to drawing some basic inferences. Let’s get to it.
mem_cas_days <- nov_23 %>%
group_by(day_of_week, day_name, member_casual) %>%
summarize(total_count=n())
## `summarise()` has grouped output by 'day_of_week', 'day_name'. You can override
## using the `.groups` argument.
mem_cas_days$day_name <- factor(mem_cas_days$day_name, levels=c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'))
as_tibble(mem_cas_days)
## # A tibble: 14 × 4
## day_of_week day_name member_casual total_count
## <dbl> <fct> <chr> <int>
## 1 1 Monday casual 24005
## 2 1 Monday member 59180
## 3 2 Tuesday casual 26837
## 4 2 Tuesday member 68543
## 5 3 Wednesday casual 23049
## 6 3 Wednesday member 56046
## 7 4 Thursday casual 19616
## 8 4 Thursday member 50279
## 9 5 Friday casual 20484
## 10 5 Friday member 43338
## 11 6 Saturday casual 25002
## 12 6 Saturday member 35709
## 13 7 Sunday casual 38078
## 14 7 Sunday member 46947
This table shows us the number of each type of user per weekday. That second chunk of code is there because I wanted the days to be in their actual order, rather than alphabetical.
From this we start to see a couple things. First, Sunday has by far the largest number of casual riders, likely because people who have a membership are probably using the bikes to get to and from work, while casual riders are using them for other things. Saturday and Tuesday seem to be runners up, with Tuesday having the most riders of any day on average. Second, ridership falls off in general toward the end of the work week. This could be due to several things, but my theory is that it’s a reflection of just…getting tired. We’ll keep an open mind, regardless.
Next up, ride times.
nov_23_mem <- filter(nov_23, member_casual == "member")
nov_23_cas <- filter(nov_23, member_casual == "casual")
avg_times_mem <- nov_23_mem %>%
group_by(mean(duration_sec)) %>%
summarize()
avg_times_cas <- nov_23_cas %>%
group_by(mean(duration_sec)) %>%
summarize()
mem_vs_cas_ridetime <- data.frame(User_Type = c("Casual", "Member"),
Average_Time = c((1372/60), (729/60))
)
as_tibble(mem_vs_cas_ridetime)
## # A tibble: 2 × 2
## User_Type Average_Time
## <chr> <dbl>
## 1 Casual 22.9
## 2 Member 12.2
Here I make a couple filtered tables that only allow records for
either members or casual riders, not both. Then I take the average ride
time in seconds and summarize it for each of the new tables, getting an
overall average ride time for both rider types.
Then I make a small dataframe that shows the resulting numbers in
minutes, and we find that overall, casual riders seem to have an average
trip length that is nearly double that of members. An interesting
insight, to be sure. One theory for this is that casual riders are more
likely to be using the bikes for recreation or leisure activities, and
so are riding for fun, rather than function.
Far be it from me to tell marketing how to do their jobs. But I’ll
try anyway.
If I had to make three recommendations for Cyclistic to convert casual
riders to annual members, it would be these:
1. Because casual members seem to be there for the experience of biking
rather than the utility of it, any digital marketing to them should
focus on the joy of riding a bike rather than the convenience.
2. Due to the number of casual riders on Sundays, and throughout the
weekend as a whole, promotional sales on annual membership could be
offered on weekend rides specifically.
3. On a more creative tack, and also to help casual riders potentially
shorten their ride times, local map printouts could be offered at bike
stations as a complimentary part of the service.
There are, of course, other insights that could be gained from some
of the data here. What stations are busiest? What times of day? What
times are more common for members or casual riders? How could weather
play a role? What areas of Chicago have the most bike traffic?
These and more are all on offer here with a little digging. For the
purposes of this case study, we’re all done, but perhaps curiosity will
demand more of me later on.