Created
March 2, 2022 00:01
-
-
Save invisiblefunnel/7b71ede23c270590a70187bb2733bc01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "placed-tennessee", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import partridge as ptg" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "6bdc029d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"inpath = \"trimet.zip\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "3a13236e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(datetime.date(2022, 1, 24), frozenset({'A.613', 'D.613', 'Q.613', 'W.613'}))" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"date, service_ids = ptg.read_busiest_date(inpath)\n", | |
"date, service_ids" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "805fa2a7", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"feed = ptg.load_feed(inpath, view={\"trips.txt\": {\"service_id\": service_ids}})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "a48549d5", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>route_id</th>\n", | |
" <th>agency_id</th>\n", | |
" <th>route_short_name</th>\n", | |
" <th>route_long_name</th>\n", | |
" <th>route_type</th>\n", | |
" <th>route_url</th>\n", | |
" <th>route_color</th>\n", | |
" <th>route_text_color</th>\n", | |
" <th>route_sort_order</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>74</th>\n", | |
" <td>90</td>\n", | |
" <td>TRIMET</td>\n", | |
" <td>NaN</td>\n", | |
" <td>MAX Red Line</td>\n", | |
" <td>0</td>\n", | |
" <td>https://trimet.org/schedules/r090.htm</td>\n", | |
" <td>D81526</td>\n", | |
" <td>FFFFFF</td>\n", | |
" <td>120</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" route_id agency_id route_short_name route_long_name route_type \\\n", | |
"74 90 TRIMET NaN MAX Red Line 0 \n", | |
"\n", | |
" route_url route_color route_text_color \\\n", | |
"74 https://trimet.org/schedules/r090.htm D81526 FFFFFF \n", | |
"\n", | |
" route_sort_order \n", | |
"74 120 " | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"feed.routes[feed.routes.route_long_name==\"MAX Red Line\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "4d0b4f7b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"max_red_line_trips = feed.trips[feed.trips.route_id==\"90\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "352a2b20", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>route_id</th>\n", | |
" <th>service_id</th>\n", | |
" <th>trip_id</th>\n", | |
" <th>direction_id</th>\n", | |
" <th>block_id</th>\n", | |
" <th>shape_id</th>\n", | |
" <th>trip_type</th>\n", | |
" <th>wheelchair_accessible</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>4418</th>\n", | |
" <td>90</td>\n", | |
" <td>A.613</td>\n", | |
" <td>11290698</td>\n", | |
" <td>0</td>\n", | |
" <td>9040</td>\n", | |
" <td>499090</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4419</th>\n", | |
" <td>90</td>\n", | |
" <td>A.613</td>\n", | |
" <td>11290699</td>\n", | |
" <td>0</td>\n", | |
" <td>9041</td>\n", | |
" <td>499089</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4420</th>\n", | |
" <td>90</td>\n", | |
" <td>A.613</td>\n", | |
" <td>11290700</td>\n", | |
" <td>0</td>\n", | |
" <td>9042</td>\n", | |
" <td>499089</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4421</th>\n", | |
" <td>90</td>\n", | |
" <td>A.613</td>\n", | |
" <td>11290701</td>\n", | |
" <td>0</td>\n", | |
" <td>9043</td>\n", | |
" <td>499089</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4422</th>\n", | |
" <td>90</td>\n", | |
" <td>A.613</td>\n", | |
" <td>11290702</td>\n", | |
" <td>0</td>\n", | |
" <td>9044</td>\n", | |
" <td>499089</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" route_id service_id trip_id direction_id block_id shape_id trip_type \\\n", | |
"4418 90 A.613 11290698 0 9040 499090 NaN \n", | |
"4419 90 A.613 11290699 0 9041 499089 NaN \n", | |
"4420 90 A.613 11290700 0 9042 499089 NaN \n", | |
"4421 90 A.613 11290701 0 9043 499089 NaN \n", | |
"4422 90 A.613 11290702 0 9044 499089 NaN \n", | |
"\n", | |
" wheelchair_accessible \n", | |
"4418 1 \n", | |
"4419 1 \n", | |
"4420 1 \n", | |
"4421 1 \n", | |
"4422 1 " | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"max_red_line_trips.head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "69ab0ee4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'A.613'}" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"set(max_red_line_trips.service_id)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment