Skip to content

Commit 489b337

Browse files
authored
Merge pull request #1148 from cal-itp/annual_ntd_outline
Start of Annual NTD Ridership Report Outline
2 parents 9e4fbbe + 7f9eacd commit 489b337

File tree

4 files changed

+745
-0
lines changed

4 files changed

+745
-0
lines changed

ntd_annual_ridership/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# NTD Annual Ridership by RTPA
2+
3+
4+
Provide CalSTA with NTD Annual Ridership by each regional transportation planning authority (RTPA)
5+
6+
This reoport shows general ridership trends by agency, mode and type of service.
7+
8+
## Dataset
9+
1. [NTD Annual Service data](https://www.transit.dot.gov/ntd/data-product/2022-annual-database-service)
10+
2. [RTPA list](https://gis.data.ca.gov/datasets/CAEnergy::regional-transportation-planning-agencies/explore?appid=cf412a17daaa47bca93c6d6b7e77aff0&edit=true)
11+
3. Download our processed data here
12+
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 8,
6+
"id": "f69ce09b-de2a-4d6e-a5b9-d6fa2ecf2be2",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from calitp_data_analysis.tables import tbls\n",
11+
"from siuba import *\n",
12+
"import pandas as pd\n",
13+
"GCS_FILE_PATH = \"gs://calitp-analytics-data/data-analyses/ntd/\"\n",
14+
"\n",
15+
"pd.set_option('display.max_rows', None) \n",
16+
"pd.set_option('display.max_columns', None) "
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 16,
22+
"id": "d92464c2-e8a2-46b4-a78e-8f25d2bb4c3f",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"# using siuba to read in data from warehouse.\n",
27+
"ntd_info = (tbls.mart_ntd.dim_annual_ntd_agency_information() \n",
28+
" >> filter(_._is_current == True,\n",
29+
" _.year == 2022,\n",
30+
" _.region == 9) \n",
31+
" >> collect()\n",
32+
" )\n",
33+
"\n",
34+
"# need to find a way to filter ntd service to California agencies only. \n",
35+
"ntd_service = (tbls.mart_ntd.dim_annual_ntd_agency_service()\n",
36+
" >> group_by(_.ntd_id)\n",
37+
" >> distinct(_.agency_name)\n",
38+
" >> collect()\n",
39+
" )#can i add pd filters after this?\n",
40+
"\n",
41+
"# reading in NTD ID crosswalk from GCS\n",
42+
"crosswalk = pd.read_csv(\n",
43+
" f\"{GCS_FILE_PATH}ntd_id_rtpa_crosswalk.csv\", \n",
44+
" dtype = {\"NTD ID\": \"str\"}\n",
45+
" ).rename(columns={\"NTD ID\": \"ntd_id\"})"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 17,
51+
"id": "a5dc49d8-6da7-422a-8482-d4bacafde914",
52+
"metadata": {},
53+
"outputs": [
54+
{
55+
"data": {
56+
"text/plain": [
57+
"(322, 46)"
58+
]
59+
},
60+
"metadata": {},
61+
"output_type": "display_data"
62+
},
63+
{
64+
"data": {
65+
"text/plain": [
66+
"(2259, 2)"
67+
]
68+
},
69+
"metadata": {},
70+
"output_type": "display_data"
71+
},
72+
{
73+
"data": {
74+
"text/plain": [
75+
"(117, 6)"
76+
]
77+
},
78+
"metadata": {},
79+
"output_type": "display_data"
80+
}
81+
],
82+
"source": [
83+
"display(\n",
84+
" ntd_info.shape,\n",
85+
" ntd_service.shape,\n",
86+
" crosswalk.shape\n",
87+
")"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 19,
93+
"id": "82a51ca6-8150-431e-8b4c-acf7be22e240",
94+
"metadata": {},
95+
"outputs": [
96+
{
97+
"data": {
98+
"text/html": [
99+
"<div>\n",
100+
"<style scoped>\n",
101+
" .dataframe tbody tr th:only-of-type {\n",
102+
" vertical-align: middle;\n",
103+
" }\n",
104+
"\n",
105+
" .dataframe tbody tr th {\n",
106+
" vertical-align: top;\n",
107+
" }\n",
108+
"\n",
109+
" .dataframe thead th {\n",
110+
" text-align: right;\n",
111+
" }\n",
112+
"</style>\n",
113+
"<table border=\"1\" class=\"dataframe\">\n",
114+
" <thead>\n",
115+
" <tr style=\"text-align: right;\">\n",
116+
" <th></th>\n",
117+
" <th>ntd_id</th>\n",
118+
" <th>agency_name</th>\n",
119+
" </tr>\n",
120+
" </thead>\n",
121+
" <tbody>\n",
122+
" <tr>\n",
123+
" <th>0</th>\n",
124+
" <td>00001</td>\n",
125+
" <td>King County Department of Metro Transit</td>\n",
126+
" </tr>\n",
127+
" <tr>\n",
128+
" <th>1</th>\n",
129+
" <td>00002</td>\n",
130+
" <td>Spokane Transit Authority</td>\n",
131+
" </tr>\n",
132+
" <tr>\n",
133+
" <th>2</th>\n",
134+
" <td>00003</td>\n",
135+
" <td>Pierce County Transportation Benefit Area Auth...</td>\n",
136+
" </tr>\n",
137+
" <tr>\n",
138+
" <th>3</th>\n",
139+
" <td>00004</td>\n",
140+
" <td>Confederated Tribes of the Colville Indian Res...</td>\n",
141+
" </tr>\n",
142+
" <tr>\n",
143+
" <th>4</th>\n",
144+
" <td>00005</td>\n",
145+
" <td>City of Everett</td>\n",
146+
" </tr>\n",
147+
" </tbody>\n",
148+
"</table>\n",
149+
"</div>"
150+
],
151+
"text/plain": [
152+
" ntd_id agency_name\n",
153+
"0 00001 King County Department of Metro Transit\n",
154+
"1 00002 Spokane Transit Authority\n",
155+
"2 00003 Pierce County Transportation Benefit Area Auth...\n",
156+
"3 00004 Confederated Tribes of the Colville Indian Res...\n",
157+
"4 00005 City of Everett"
158+
]
159+
},
160+
"execution_count": 19,
161+
"metadata": {},
162+
"output_type": "execute_result"
163+
}
164+
],
165+
"source": [
166+
"ntd_service.head()"
167+
]
168+
},
169+
{
170+
"cell_type": "code",
171+
"execution_count": null,
172+
"id": "c025cbe8-6752-43c8-ba36-0eeb368fdd9c",
173+
"metadata": {},
174+
"outputs": [],
175+
"source": []
176+
}
177+
],
178+
"metadata": {
179+
"kernelspec": {
180+
"display_name": "Python 3 (ipykernel)",
181+
"language": "python",
182+
"name": "python3"
183+
},
184+
"language_info": {
185+
"codemirror_mode": {
186+
"name": "ipython",
187+
"version": 3
188+
},
189+
"file_extension": ".py",
190+
"mimetype": "text/x-python",
191+
"name": "python",
192+
"nbconvert_exporter": "python",
193+
"pygments_lexer": "ipython3",
194+
"version": "3.9.13"
195+
}
196+
},
197+
"nbformat": 4,
198+
"nbformat_minor": 5
199+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "34028321-6cdf-4264-867b-97f042d6d871",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%%capture\n",
11+
"import sys\n",
12+
"sys.path.append(\"../bus_service_increase\")\n",
13+
"\n",
14+
"import warnings\n",
15+
"warnings.filterwarnings('ignore')\n",
16+
"\n",
17+
"import altair as alt\n",
18+
"import calitp_data_analysis.magics\n",
19+
"import pandas as pd\n",
20+
"\n",
21+
"from IPython.display import display, HTML\n",
22+
"\n",
23+
"from bus_service_utils import chart_utils\n",
24+
"from calitp_data_analysis import calitp_color_palette as cp\n",
25+
"#from update_vars import GCS_FILE_PATH, PUBLIC_FILENAME, YEAR, MONTH\n",
26+
"#from monthly_ridership_by_rtpa import get_percent_change\n",
27+
"#from shared_utils.rt_dates import MONTH_DICT\n",
28+
"\n",
29+
"#alt.renderers.enable(\"html\")\n",
30+
"alt.data_transformers.enable('default', max_rows=None)"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "6437e80c-fa8a-433f-b2aa-7138360d04a1",
37+
"metadata": {
38+
"tags": [
39+
"parameter"
40+
]
41+
},
42+
"outputs": [],
43+
"source": [
44+
"# parameters cell for local\n",
45+
"rtpa = \"Metropolitan Transportation Commission\""
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"id": "b7055fb6-4331-425e-b4e5-e896b11b3acd",
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"%%capture_parameters\n",
56+
"rtpa"
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"id": "8e07bb7c-ae9c-49ca-a875-9f3e2037d5f8",
62+
"metadata": {},
63+
"source": [
64+
"# {rtpa}\n",
65+
"## Annual Ridership Trends\n",
66+
"\n",
67+
"**Download data from our public [folder](https://console.cloud.google.com/storage/browser/calitp-publish-data-analysis)** by navigating to `ntd_annual_ridership` and selecting a file."
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"id": "9e285f5a-6c01-4c99-a442-a816ebe3ed63",
73+
"metadata": {},
74+
"source": [
75+
"### Transit Agency"
76+
]
77+
},
78+
{
79+
"cell_type": "markdown",
80+
"id": "888db6c8-df34-4399-93bd-1eced6fd6b09",
81+
"metadata": {},
82+
"source": [
83+
"### Transit Mode"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"id": "e86a399b-1682-49c4-b9cc-cbdd2691777b",
89+
"metadata": {},
90+
"source": [
91+
"### Type of Service"
92+
]
93+
}
94+
],
95+
"metadata": {
96+
"kernelspec": {
97+
"display_name": "Python 3 (ipykernel)",
98+
"language": "python",
99+
"name": "python3"
100+
},
101+
"language_info": {
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"file_extension": ".py",
107+
"mimetype": "text/x-python",
108+
"name": "python",
109+
"nbconvert_exporter": "python",
110+
"pygments_lexer": "ipython3",
111+
"version": "3.9.13"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 5
116+
}

0 commit comments

Comments
 (0)