13 Analysing Chicago Bike Times
author: Daniel Slutsky last update: 2024-10-23
This tutorial demonstrates a simple analysis of time patterns in transportation data.
13.1 Question
Can we distinguish weekends from weekdays in terms of the hours in which people tend to use their bikes?
13.2 Setup
ns chicago-bike-times
(:require [tablecloth.api :as tc]
(:as datetime]
[tech.v3.datatype.datetime :as hanami]
[scicloj.tableplot.v1.hanami :as kind])) [scicloj.kindly.v4.kind
13.3 Reading data
You may learn more about the Cyclistic Bike Share 2023 dataset in our Chicago bike trips tutorial.
defonce raw-trips
(-> "data/chicago-bikes/202304_divvy_tripdata.csv.gz"
(:key-fn keyword
(tc/dataset {:parser-fn {"started_at"
:local-date-time
["yyyy-MM-dd HH:mm:ss"]
"ended_at"
:local-date-time
["yyyy-MM-dd HH:mm:ss"]}})))
13.4 Processing data
def processed-trips
(-> raw-trips
(:hour (fn [ds]
(tc/add-columns {->> ds
(:started_at
(datetime/long-temporal-field:hours)))
:day-of-week (fn [ds]
->> ds
(:started_at
(datetime/long-temporal-field:day-of-week)))})))
13.5 Analysis
-> processed-trips
(:hour])
(tc/group-by [:n tc/row-count})
(tc/aggregate {:hour])
(tc/order-by [:hour
(hanami/layer-bar {:=x :n})) :=y
-> processed-trips
(:day-of-week :hour])
(tc/group-by [:n tc/row-count})
(tc/aggregate {:day-of-week])
(tc/group-by [
(tc/process-group-data #(hanami/layer-bar%
:hour
{:=x :n}))
:=y kind/table)
name | group-id | data |
---|---|---|
|
0 | |
|
1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 |
13.6 Conclusion
Yes. Weekends are different from weekdays in terms of the hours in which people tend to use their bikes.