|
| 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 | +} |
0 commit comments