diff --git a/notebooks/data_cyril.ipynb b/notebooks/data_cyril.ipynb index 393b35e..b83daf0 100644 --- a/notebooks/data_cyril.ipynb +++ b/notebooks/data_cyril.ipynb @@ -1,3864 +1,4042 @@ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Current session configs: {'conf': {'spark.app.name': 'lgptguys_final'}, 'kind': 'pyspark'}
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
IDYARN Application IDKindStateSpark UIDriver logCurrent session?
7611application_1589299642358_2106pysparkidleLinkLink
7632application_1589299642358_2126pysparkidleLinkLink
7633application_1589299642358_2127pysparkbusyLinkLink
7635application_1589299642358_2129pysparkidleLinkLink
7640application_1589299642358_2135pysparkidleLinkLink
7642application_1589299642358_2138pysparkidleLinkLink
7644application_1589299642358_2140pysparkbusyLinkLink
7651application_1589299642358_2147pysparkidleLinkLink
7653application_1589299642358_2149pysparkidleLinkLink
7664application_1589299642358_2160pysparkidleLinkLink
7665application_1589299642358_2161pysparkidleLinkLink
7667application_1589299642358_2163pysparkidleLinkLink
7670application_1589299642358_2166pysparkidleLinkLink
7674application_1589299642358_2170pysparkidleLinkLink
7675application_1589299642358_2171pysparkidleLinkLink
7676application_1589299642358_2172pysparkbusyLinkLink
7677application_1589299642358_2173pysparkbusyLinkLink
7678application_1589299642358_2174pysparkidleLinkLink
7680application_1589299642358_2176pysparkidleLinkLink
7681application_1589299642358_2177pysparkidleLinkLink
7683application_1589299642358_2179pysparkidleLinkLink
7684application_1589299642358_2180pysparkbusyLinkLink
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%configure\n", "{\"conf\": {\n", " \"spark.app.name\": \"lgptguys_final\"\n", "}}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting Spark application\n" ] }, { "data": { "text/html": [ "\n", "
IDYARN Application IDKindStateSpark UIDriver logCurrent session?
7685application_1589299642358_2181pysparkidleLinkLink
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "SparkSession available as 'spark'.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "An error was encountered:\n", "unknown magic command '%spark'\n", "UnknownMagic: unknown magic command '%spark'\n", "\n" ] } ], "source": [ "# Initialization\n", "%%spark" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below, we pre-process the data to generate the files required to run RAPTOR.\n", "\n", "The main reasoning behind this way of cleaning the data is the following:\n", "**Given a cleaned stop_times.txt file, it is possible to reconstruct everything required to run RAPTOR** to the exception of footpaths. In particular, routes are reconstructed from the cleaned stop_times.txt and not from routes.txt.\n", "\n", "We use the following strategy:\n", "\n", "- 1) Filter out stops out of 15km of ZH HB\n", " - Done on stops\n", "- 2) Merge stops that share a parent stop to the first 7 characters of the stop name\n", " - Done on stops (add a general_stop column)\n", " - Used as an input for stopTimes (add a general_stop column). At this point, stop_times contains only stops within 15km of ZH HB\n", " \n", "- 3) keep only services that run each day of the business week:\n", " - Obtain the list of services from calendar\n", " - Serves as an input to filter trips\n", " - Serves as an input to filter stop_times\n", "- 4) keep only stop times between 7am and 7pm\n", " - Do that on stop_times\n", " \n", "- 5) Find unique trips, based on the stops sequence and the departure times sequence\n", " - sort by trip, arrival_time (which is the same as stop_sequence)\n", " - build a (sorted) all_stops column for each trip\n", " - build a (sorted) all_departure_times column for each trip\n", " - keep only one trip that has the same all_stops and all_departure_times column\n", "- 6) building routes based on unique trips\n", " - order unique_trips by stop_sequence, earliest departure time\n", " - each window with the same stop_sequence gets a unique routeID\n", " \n", "- 7) giving unique integer indices to stops\n", " - get unique general (parent) stop names from stop times\n", " - assign an index with zipWithIndex\n", " - stop_times -> inner join on result\n", "- 8) indicating transport type from the route\n", " - inner join stop_times with routes.txt on route_id" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from geopy.distance import great_circle\n", "from pyspark.sql.functions import *\n", "import numpy as np\n", "import pandas as pd\n", "from geopy.distance import great_circle\n", "from pyspark.sql.types import DoubleType\n", "from pyspark.sql.types import DateType" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1) Filtering out stops not within 15km of ZH HB" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-------+--------------------+----------------+-----------------+-------------+--------------+\n", "|stop_id| stop_name| stop_lat| stop_lon|location_type|parent_station|\n", "+-------+--------------------+----------------+-----------------+-------------+--------------+\n", "|1322000| Altoggio|46.1672513851495| 8.345807131427| null| null|\n", "|1322001| Antronapiana| 46.060121674738| 8.11361957990831| null| null|\n", "|1322002| Anzola|45.9898698225697| 8.34571729989858| null| null|\n", "|1322003| Baceno|46.2614983591677| 8.31925293162473| null| null|\n", "|1322004|Beura Cardezza, c...|46.0790618438814| 8.29927439970313| null| null|\n", "|1322005|Bognanco, T. Vill...|46.1222963432243| 8.21077237789936| null| null|\n", "|1322006| Boschetto|46.0656504576122| 8.26113193273411| null| null|\n", "|1322007| Cadarese|46.2978807772998| 8.3626325767009| null| null|\n", "|1322010| Campioli|45.9695691829797| 8.04585965801774| null| null|\n", "|1322011| Cascate del Toce|46.4091810825782| 8.4117524564434| null| null|\n", "|1322012| Castiglione|46.0205875326422| 8.2148866619012| null| null|\n", "|1322013| Ceppo Morelli|45.9710364221151| 8.06992552448265| null| null|\n", "|1322014|Chiesa (Val Forma...|46.3530849443472| 8.42787721579558| null| null|\n", "|1322015| Cosasca di Trontano|46.0967496675661| 8.31182386422403| null| null|\n", "|1322016| Cresti|46.0664046229574| 8.2328978833503| null| null|\n", "|1322017| Crevoladossola|46.1562758593614| 8.30343359946918| null| null|\n", "|1322018| Crodo, Bagni|46.2141837457637| 8.32131905677849| null| null|\n", "|1322019| Crodo, paese| 46.224016613202| 8.3235648449891| null| null|\n", "|1322021| Croppo di Trontano|46.1103590121829| 8.31194064521098| null| null|\n", "|1322022| Crusinallo|45.6945937446539|0.595870494345107| null| null|\n", "+-------+--------------------+----------------+-----------------+-------------+--------------+\n", "only showing top 20 rows" ] } ], "source": [ "stops = spark.read.csv(\"/data/sbb/timetables/csv/stops/2019/05/14/stops.txt\", header=True, sep = \",\")\n", "stops.show()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "30631" ] } ], "source": [ "stops.count()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#defining udf function\n", "@udf(\"float\")\n", "def great_circle_udf(x, y):\n", " return great_circle(x, y).kilometers" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+--------------------+----------------+----------------+-------------+--------------+\n", "| stop_id| stop_name| stop_lat| stop_lon|location_type|parent_station|\n", "+-----------+--------------------+----------------+----------------+-------------+--------------+\n", "| 8500926|Oetwil a.d.L., Sc...|47.4236270123012| 8.4031825286317| null| null|\n", "| 8502186|Dietikon Stoffelbach|47.3934058321612|8.39894248049007| null| 8502186P|\n", "|8502186:0:1|Dietikon Stoffelbach|47.3934666445388|8.39894248049007| null| 8502186P|\n", "|8502186:0:2|Dietikon Stoffelbach|47.3935274568464|8.39894248049007| null| 8502186P|\n", "| 8502186P|Dietikon Stoffelbach|47.3934058321612|8.39894248049007| 1| null|\n", "| 8502187|Rudolfstetten Hof...|47.3646945560768|8.37709545277724| null| 8502187P|\n", "|8502187:0:1|Rudolfstetten Hof...|47.3647554015789|8.37709545277724| null| 8502187P|\n", "|8502187:0:2|Rudolfstetten Hof...|47.3648162470108|8.37709545277724| null| 8502187P|\n", "| 8502187P|Rudolfstetten Hof...|47.3646945560768|8.37709545277724| 1| null|\n", "| 8502188| Zufikon Hammergut|47.3558347019549|8.35472740219955| null| 8502188P|\n", "|8502188:0:1| Zufikon Hammergut|47.3558955576756|8.35472740219955| null| 8502188P|\n", "|8502188:0:2| Zufikon Hammergut|47.3559564133261|8.35472740219955| null| 8502188P|\n", "| 8502188P| Zufikon Hammergut|47.3558347019549|8.35472740219955| 1| null|\n", "| 8502208| Horgen Oberdorf|47.2587475534877|8.58979854578067| null| 8502208P|\n", "|8502208:0:2| Horgen Oberdorf|47.2589304560815|8.58979854578067| null| 8502208P|\n", "|8502208:0:3| Horgen Oberdorf|47.2588085210892|8.58979854578067| null| 8502208P|\n", "|8502208:0:4| Horgen Oberdorf|47.2588694886204|8.58979854578067| null| 8502208P|\n", "| 8502208P| Horgen Oberdorf|47.2587475534877|8.58979854578067| 1| null|\n", "| 8502209| Oberrieden Dorf|47.2767238569466| 8.577635356832| null| 8502209P|\n", "|8502209:0:1| Oberrieden Dorf|47.2768457506749| 8.577635356832| null| 8502209P|\n", "+-----------+--------------------+----------------+----------------+-------------+--------------+\n", "only showing top 20 rows" ] } ], "source": [ "# Zurich HB coordinates\n", "zurich_geo = (47.378177, 8.540192)\n", "\n", "#transforming Zurich HB coordinates in a spark dataframe column object\n", "zurich_geo_col = struct(lit(zurich_geo[0]), lit(zurich_geo[1]))\n", "\n", "#applying filter function based on distance\n", "stops_15km = stops.filter(great_circle_udf(zurich_geo_col, struct(stops.stop_lat, stops.stop_lon)) < 15)\n", "stops_15km.show()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "1883" ] } ], "source": [ "stops_15km.count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2) Merging stops that share a parent stop" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+------------+--------------------+----------------+----------------+-------------+--------------+\n", "| stop_id| stop_name| stop_lat| stop_lon|location_type|parent_station|\n", "+------------+--------------------+----------------+----------------+-------------+--------------+\n", "| 8502186|Dietikon Stoffelbach|47.3934058321612|8.39894248049007| null| 8502186P|\n", "| 8502186:0:1|Dietikon Stoffelbach|47.3934666445388|8.39894248049007| null| 8502186P|\n", "| 8502186:0:2|Dietikon Stoffelbach|47.3935274568464|8.39894248049007| null| 8502186P|\n", "| 8502187|Rudolfstetten Hof...|47.3646945560768|8.37709545277724| null| 8502187P|\n", "| 8502187:0:1|Rudolfstetten Hof...|47.3647554015789|8.37709545277724| null| 8502187P|\n", "| 8502187:0:2|Rudolfstetten Hof...|47.3648162470108|8.37709545277724| null| 8502187P|\n", "| 8502188| Zufikon Hammergut|47.3558347019549|8.35472740219955| null| 8502188P|\n", "| 8502188:0:1| Zufikon Hammergut|47.3558955576756|8.35472740219955| null| 8502188P|\n", "| 8502188:0:2| Zufikon Hammergut|47.3559564133261|8.35472740219955| null| 8502188P|\n", "| 8502208| Horgen Oberdorf|47.2587475534877|8.58979854578067| null| 8502208P|\n", "| 8502208:0:2| Horgen Oberdorf|47.2589304560815|8.58979854578067| null| 8502208P|\n", "| 8502208:0:3| Horgen Oberdorf|47.2588085210892|8.58979854578067| null| 8502208P|\n", "| 8502208:0:4| Horgen Oberdorf|47.2588694886204|8.58979854578067| null| 8502208P|\n", "| 8502209| Oberrieden Dorf|47.2767238569466| 8.577635356832| null| 8502209P|\n", "| 8502209:0:1| Oberrieden Dorf|47.2768457506749| 8.577635356832| null| 8502209P|\n", "| 8502209:0:2| Oberrieden Dorf|47.2767848038458| 8.577635356832| null| 8502209P|\n", "| 8502220| Urdorf|47.3908820565997|8.43471339510869| null| 8502220P|\n", "| 8502220:0:1| Urdorf|47.3909428718897|8.43471339510869| null| 8502220P|\n", "| 8502220:0:2| Urdorf|47.3910036871096|8.43471339510869| null| 8502220P|\n", "| 8502221| Birmensdorf ZH|47.3574351840587|8.43754308825406| null| 8502221P|\n", "| 8502221:0:1| Birmensdorf ZH|47.3575568917382|8.43754308825406| null| 8502221P|\n", "| 8502221:0:2| Birmensdorf ZH|47.3574960379336|8.43754308825406| null| 8502221P|\n", "| 8502222| Bonstetten-Wettswil|47.3258973534906|8.46817563944679| null| 8502222P|\n", "| 8502222:0:2| Bonstetten-Wettswil| 47.325958243729|8.46817563944679| null| 8502222P|\n", "| 8502222:0:3| Bonstetten-Wettswil|47.3260191338971|8.46817563944679| null| 8502222P|\n", "| 8502223| Hedingen|47.2987820476816|8.44595131931459| null| 8502223P|\n", "| 8502223:0:1| Hedingen|47.2988429691695|8.44595131931459| null| 8502223P|\n", "| 8502223:0:2| Hedingen|47.2989038905872|8.44595131931459| null| 8502223P|\n", "| 8502224| Affoltern am Albis|47.2760656259617|8.44658014001356| null| 8502224P|\n", "| 8502224:0:1| Affoltern am Albis|47.2761875212063|8.44658014001356| null| 8502224P|\n", "| 8502224:0:2| Affoltern am Albis|47.2762484687233|8.44658014001356| null| 8502224P|\n", "| 8502224:0:3| Affoltern am Albis|47.2761265736191|8.44658014001356| null| 8502224P|\n", "| 8502229:0:1| Urdorf Weihermatt|47.3810351357388|8.43032961652157| null| 8502229P|\n", "| 8502229:0:2| Urdorf Weihermatt|47.3810959623905|8.43032961652157| null| 8502229P|\n", "| 8502273:0:1| Bremgarten|47.3519945640447| 8.3474779978557| null| 8502273P|\n", "| 8502273:0:2| Bremgarten|47.3519337038252| 8.3474779978557| null| 8502273P|\n", "| 8502276:0:1| Berikon-Widen|47.3622485087742|8.36679177646695| null| 8502276P|\n", "| 8502276:0:2| Berikon-Widen|47.3623093570976|8.36679177646695| null| 8502276P|\n", "| 8502758:0:A|Hausen am Albis, ...|47.2448085174147| 8.5329801040522| null| 8502758P|\n", "| 8502758:0:B|Hausen am Albis, ...|47.2448695010648| 8.5329801040522| null| 8502758P|\n", "| 8502758:0:C|Hausen am Albis, ...|47.2449304846447| 8.5329801040522| null| 8502758P|\n", "| 8503000| Zürich HB|47.3781762039461|8.54019357578468| null| 8503000P|\n", "|8503000:0:10| Zürich HB|47.3794536181612|8.54019357578468| null| 8503000P|\n", "|8503000:0:11| Zürich HB|47.3795144466376|8.54019357578468| null| 8503000P|\n", "|8503000:0:12| Zürich HB|47.3786020121232|8.54019357578468| null| 8503000P|\n", "|8503000:0:13| Zürich HB|47.3785411825942|8.54019357578468| null| 8503000P|\n", "|8503000:0:14| Zürich HB|47.3783586935859|8.54019357578468| null| 8503000P|\n", "|8503000:0:15| Zürich HB|47.3784803529949|8.54019357578468| null| 8503000P|\n", "|8503000:0:16| Zürich HB|47.3784195233255|8.54019357578468| null| 8503000P|\n", "|8503000:0:17| Zürich HB| 47.379271132311|8.54019357578468| null| 8503000P|\n", "+------------+--------------------+----------------+----------------+-------------+--------------+\n", "only showing top 50 rows" ] } ], "source": [ "stops_15km.filter(stops_15km.parent_station.isNotNull()).show(50)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+--------------------+----------------+----------------+-------------+--------------+\n", "| stop_id| stop_name| stop_lat| stop_lon|location_type|parent_station|\n", "+-----------+--------------------+----------------+----------------+-------------+--------------+\n", "| 8500926|Oetwil a.d.L., Sc...|47.4236270123012| 8.4031825286317| null| null|\n", "| 8502186P|Dietikon Stoffelbach|47.3934058321612|8.39894248049007| 1| null|\n", "| 8502187P|Rudolfstetten Hof...|47.3646945560768|8.37709545277724| 1| null|\n", "| 8502188P| Zufikon Hammergut|47.3558347019549|8.35472740219955| 1| null|\n", "| 8502208P| Horgen Oberdorf|47.2587475534877|8.58979854578067| 1| null|\n", "| 8502209P| Oberrieden Dorf|47.2767238569466| 8.577635356832| 1| null|\n", "| 8502220P| Urdorf|47.3908820565997|8.43471339510869| 1| null|\n", "| 8502221P| Birmensdorf ZH|47.3574351840587|8.43754308825406| 1| null|\n", "| 8502222P| Bonstetten-Wettswil|47.3258973534906|8.46817563944679| 1| null|\n", "| 8502223P| Hedingen|47.2987820476816|8.44595131931459| 1| null|\n", "| 8502224P| Affoltern am Albis|47.2760656259617|8.44658014001356| 1| null|\n", "| 8502229P| Urdorf Weihermatt|47.3809743090169|8.43032961652157| 1| null|\n", "| 8502268| Zufikon Belvédère|47.3575812332404|8.35923694492646| null| null|\n", "|8502268:0:1| Zufikon Belvédère|47.3576420869468|8.35923694492646| null| null|\n", "| 8502270| Bergfrieden|47.3977111751049|8.39908621093555| null| null|\n", "|8502270:0:1| Bergfrieden|47.3977719825142|8.39908621093555| null| null|\n", "| 8502273P| Bremgarten|47.3518728435356| 8.3474779978557| 1| null|\n", "| 8502274| Zufikon|47.3525240449924|8.35470943589386| null| null|\n", "|8502274:0:1| Zufikon|47.3525849045311|8.35470943589386| null| null|\n", "| 8502275| Widen Heinrüti|47.3620598785256|8.35486214949218| null| null|\n", "|8502275:0:1| Widen Heinrüti|47.3621207270666|8.35486214949218| null| null|\n", "| 8502276P| Berikon-Widen|47.3621876603806|8.36679177646695| 1| null|\n", "| 8502277| Rudolfstetten|47.3700243558558|8.38180262486668| null| null|\n", "|8502277:0:1| Rudolfstetten| 47.37008519521|8.38180262486668| null| null|\n", "| 8502278| Reppischhof|47.3847211041004| 8.3963463493186| null| null|\n", "|8502278:0:1| Reppischhof|47.3847819264993| 8.3963463493186| null| null|\n", "| 8502495|Zürich Wollishofe...|47.3476976601166|8.53331248070737| null| null|\n", "| 8502508|Spreitenbach, Rai...|47.4154457211288|8.37718528430566| null| null|\n", "| 8502553|Unterlunkhofen, B...|47.3221585583935| 8.380473118246| null| null|\n", "| 8502559|Waldegg, Birmensd...|47.3683025730349|8.46346846735736| null| null|\n", "| 8502560| Berikon, Kirche|47.3510512227562|8.37141810018081| null| null|\n", "| 8502570| Rottenschwil, Hecht|47.3190589331876| 8.372091836644| null| null|\n", "| 8502572|Zürich, Goldbrunn...|47.3702920484894|8.51391785372053| null| null|\n", "| 8502574|Affoltern a. A., ...|47.2784669105587|8.45910265507593| null| null|\n", "| 8502575| Widen, Dorf|47.3675724714769|8.36359377405504| null| null|\n", "| 8502750| Bellikon, Post|47.3895076123306| 8.3433726970067| null| null|\n", "| 8502758P|Hausen am Albis, ...|47.2447475336943| 8.5329801040522| 1| null|\n", "| 8502762|Langnau a.A., Alb...|47.2761509526624|8.52069115096373| null| null|\n", "| 8502763|Hausen am Albis, ...|47.2629785384073|8.51724162027223| null| null|\n", "| 8502764|Hausen am Albis, ...|47.2590158104091| 8.5220386238901| null| null|\n", "| 8502771|Aeugst am Albis, ...|47.2678309520619|8.48534244452871| null| null|\n", "| 8502776|Gattikon, Obstgarten|47.2847255843239| 8.5511170896411| null| null|\n", "| 8502779| Ottenbach, Post|47.2816481400898|8.40452101840523| null| null|\n", "| 8502876|Aesch ZH, Gemeind...|47.3382079319594|8.43870191497073| null| null|\n", "| 8502879| Jonen, Post|47.2961806346557|8.39551091610425| null| null|\n", "| 8502883|Zwillikon, Gemein...|47.2873945890065|8.43218912915996| null| null|\n", "| 8502885|Bonstetten, Dorfp...|47.3150882242354|8.46778038072173| null| null|\n", "| 8502894|Oberwil-Lieli, Ob...|47.3371669407057|8.38639301596917| null| null|\n", "| 8502950|Birmensdorf ZH, Z...|47.3539359682156|8.43717477898752| null| null|\n", "| 8502953|Affoltern a. A., ...|47.2812215495339|8.45441344929217| null| null|\n", "+-----------+--------------------+----------------+----------------+-------------+--------------+\n", "only showing top 50 rows" ] } ], "source": [ "stops_15km.filter(stops_15km.parent_station.isNull()).show(50)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is clear that parent stops were not properly assigned for all stops (e.g Zufikon Belvédère where there is a platform stop, but no parent stop). Thus, we create a new column `stop_id_general` that contains only the 7 first characters of `stop_id`" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+--------------------+----------------+----------------+-------------+--------------+---------------+\n", "| stop_id| stop_name| stop_lat| stop_lon|location_type|parent_station|stop_id_general|\n", "+-----------+--------------------+----------------+----------------+-------------+--------------+---------------+\n", "| 8500926|Oetwil a.d.L., Sc...|47.4236270123012| 8.4031825286317| null| null| 8500926|\n", "| 8502186|Dietikon Stoffelbach|47.3934058321612|8.39894248049007| null| 8502186P| 8502186|\n", "|8502186:0:1|Dietikon Stoffelbach|47.3934666445388|8.39894248049007| null| 8502186P| 8502186|\n", "|8502186:0:2|Dietikon Stoffelbach|47.3935274568464|8.39894248049007| null| 8502186P| 8502186|\n", "| 8502186P|Dietikon Stoffelbach|47.3934058321612|8.39894248049007| 1| null| 8502186|\n", "| 8502187|Rudolfstetten Hof...|47.3646945560768|8.37709545277724| null| 8502187P| 8502187|\n", "|8502187:0:1|Rudolfstetten Hof...|47.3647554015789|8.37709545277724| null| 8502187P| 8502187|\n", "|8502187:0:2|Rudolfstetten Hof...|47.3648162470108|8.37709545277724| null| 8502187P| 8502187|\n", "| 8502187P|Rudolfstetten Hof...|47.3646945560768|8.37709545277724| 1| null| 8502187|\n", "| 8502188| Zufikon Hammergut|47.3558347019549|8.35472740219955| null| 8502188P| 8502188|\n", "|8502188:0:1| Zufikon Hammergut|47.3558955576756|8.35472740219955| null| 8502188P| 8502188|\n", "|8502188:0:2| Zufikon Hammergut|47.3559564133261|8.35472740219955| null| 8502188P| 8502188|\n", "| 8502188P| Zufikon Hammergut|47.3558347019549|8.35472740219955| 1| null| 8502188|\n", "| 8502208| Horgen Oberdorf|47.2587475534877|8.58979854578067| null| 8502208P| 8502208|\n", "|8502208:0:2| Horgen Oberdorf|47.2589304560815|8.58979854578067| null| 8502208P| 8502208|\n", "|8502208:0:3| Horgen Oberdorf|47.2588085210892|8.58979854578067| null| 8502208P| 8502208|\n", "|8502208:0:4| Horgen Oberdorf|47.2588694886204|8.58979854578067| null| 8502208P| 8502208|\n", "| 8502208P| Horgen Oberdorf|47.2587475534877|8.58979854578067| 1| null| 8502208|\n", "| 8502209| Oberrieden Dorf|47.2767238569466| 8.577635356832| null| 8502209P| 8502209|\n", "|8502209:0:1| Oberrieden Dorf|47.2768457506749| 8.577635356832| null| 8502209P| 8502209|\n", "+-----------+--------------------+----------------+----------------+-------------+--------------+---------------+\n", "only showing top 20 rows" ] } ], "source": [ "stops_15km = stops_15km.withColumn('stop_id_general',col('stop_id').substr(1, 7))\n", "stops_15km.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we filter stop_times with the 15km radius, and add the stop_id_general column" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+---------------+--------------------+\n", "| stop_id|stop_id_general| stop_name|\n", "+-----------+---------------+--------------------+\n", "| 8500926| 8500926|Oetwil a.d.L., Sc...|\n", "| 8502186| 8502186|Dietikon Stoffelbach|\n", "|8502186:0:1| 8502186|Dietikon Stoffelbach|\n", "|8502186:0:2| 8502186|Dietikon Stoffelbach|\n", "| 8502186P| 8502186|Dietikon Stoffelbach|\n", "| 8502187| 8502187|Rudolfstetten Hof...|\n", "|8502187:0:1| 8502187|Rudolfstetten Hof...|\n", "|8502187:0:2| 8502187|Rudolfstetten Hof...|\n", "| 8502187P| 8502187|Rudolfstetten Hof...|\n", "| 8502188| 8502188| Zufikon Hammergut|\n", "|8502188:0:1| 8502188| Zufikon Hammergut|\n", "|8502188:0:2| 8502188| Zufikon Hammergut|\n", "| 8502188P| 8502188| Zufikon Hammergut|\n", "| 8502208| 8502208| Horgen Oberdorf|\n", "|8502208:0:2| 8502208| Horgen Oberdorf|\n", "|8502208:0:3| 8502208| Horgen Oberdorf|\n", "|8502208:0:4| 8502208| Horgen Oberdorf|\n", "| 8502208P| 8502208| Horgen Oberdorf|\n", "| 8502209| 8502209| Oberrieden Dorf|\n", "|8502209:0:1| 8502209| Oberrieden Dorf|\n", "+-----------+---------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stops_15km_for_join = stops_15km.select(stops_15km.stop_id, stops_15km.stop_id_general, stops.stop_name)\n", "stops_15km_for_join.show()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+------------+--------------+-----------+-------------+-----------+-------------+\n", "| trip_id|arrival_time|departure_time| stop_id|stop_sequence|pickup_type|drop_off_type|\n", "+--------------------+------------+--------------+-----------+-------------+-----------+-------------+\n", "|1.TA.1-1-B-j19-1.1.R| 04:20:00| 04:20:00|8500010:0:3| 1| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:24:00| 04:24:00|8500020:0:3| 2| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:28:00| 04:28:00|8500021:0:5| 3| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:30:00| 04:30:00|8517131:0:2| 4| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:32:00| 04:32:00|8500300:0:5| 5| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:35:00| 04:35:00|8500313:0:2| 6| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:37:00| 04:38:00|8500301:0:3| 7| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:40:00| 04:41:00|8500302:0:3| 8| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:45:00| 04:45:00|8500303:0:2| 9| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:48:00| 04:49:00|8500320:0:3| 10| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:52:00| 04:52:00|8500304:0:2| 11| 0| 0|\n", "|1.TA.1-1-B-j19-1.1.R| 04:56:00| 04:56:00|8500305:0:1| 12| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 05:50:00| 05:50:00|8500010:0:3| 1| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 05:54:00| 05:54:00|8500020:0:3| 2| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 05:58:00| 05:58:00|8500021:0:5| 3| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 06:00:00| 06:00:00|8517131:0:2| 4| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 06:02:00| 06:02:00|8500300:0:5| 5| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 06:05:00| 06:05:00|8500313:0:2| 6| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 06:07:00| 06:08:00|8500301:0:3| 7| 0| 0|\n", "|25.TA.1-1-B-j19-1...| 06:10:00| 06:11:00|8500302:0:3| 8| 0| 0|\n", "+--------------------+------------+--------------+-----------+-------------+-----------+-------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times = spark.read.csv(\"/data/sbb/timetables/csv/stop_times/2019/05/14/stop_times.txt\", header=True, sep = \",\")\n", "stop_times.show()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "11128930" ] } ], "source": [ "stop_times.count()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+--------------------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+\n", "| stop_id| trip_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name|\n", "+-----------+--------------------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+\n", "|8503202:0:4|8.TA.25-70-j19-1.1.H| 14:13:00| 14:14:00| 3| 0| 0| 8503202| Thalwil|\n", "|8503000:0:8|14.TA.25-70-j19-1...| 20:04:00| 20:04:00| 1| 0| 0| 8503000| Zürich HB|\n", "|8503202:0:5|108.TA.25-75-j19-...| 21:12:00| 21:14:00| 5| 0| 0| 8503202| Thalwil|\n", "|8503000:0:7|263.TA.25-75-j19-...| 16:35:00| 16:35:00| 1| 0| 0| 8503000| Zürich HB|\n", "| 8588051|3.TA.26-811-j19-1...| 17:31:00| 17:31:00| 2| 0| 0| 8588051| Uster, Dammstrasse|\n", "| 8573504|45.TA.26-811-j19-...| 06:41:00| 06:41:00| 11| 0| 0| 8573504| Uster, Bahnhof|\n", "| 8588052|63.TA.26-811-j19-...| 10:18:00| 10:18:00| 4| 0| 0| 8588052| Uster, Gschwader|\n", "| 8503152|69.TA.26-811-j19-...| 16:51:00| 16:51:00| 7| 0| 0| 8503152| Uster, Brandschenke|\n", "| 8503152|71.TA.26-811-j19-...| 09:51:00| 09:51:00| 7| 0| 0| 8503152| Uster, Brandschenke|\n", "| 8587860|81.TA.26-811-j19-...| 16:08:00| 16:08:00| 9| 0| 0| 8587860| Uster, Strick|\n", "| 8587860|85.TA.26-811-j19-...| 16:32:00| 16:32:00| 3| 0| 0| 8587860| Uster, Strick|\n", "| 8588053|104.TA.26-811-j19...| 23:50:00| 23:50:00| 6| 0| 0| 8588053| Uster, Haberweid|\n", "| 8503152|127.TA.26-811-j19...| 13:51:00| 13:51:00| 7| 0| 0| 8503152| Uster, Brandschenke|\n", "| 8573504|150.TA.26-811-j19...| 07:45:00| 07:45:00| 1| 0| 0| 8573504| Uster, Bahnhof|\n", "| 8588055|165.TA.26-811-j19...| 20:24:00| 20:24:00| 10| 0| 0| 8588055|Uster, Oberlandst...|\n", "| 8591857|180.TA.26-811-j19...| 11:52:00| 11:52:00| 8| 0| 0| 8591857| Uster, Loren-Allee|\n", "| 8503152|184.TA.26-811-j19...| 11:51:00| 11:51:00| 7| 0| 0| 8503152| Uster, Brandschenke|\n", "| 8588058|2.TA.26-812-j19-1...| 24:23:00| 24:23:00| 10| 1| 0| 8588058| Uster, Wageren|\n", "| 8588056|6.TA.26-812-j19-1...| 17:52:00| 17:52:00| 9| 0| 0| 8588056| Uster, Talweg|\n", "| 8588059|44.TA.26-812-j19-...| 18:19:00| 18:19:00| 6| 0| 0| 8588059| Uster, Weidli|\n", "+-----------+--------------------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times_15km = stop_times.join(stops_15km_for_join, how=\"inner\", on = \"stop_id\").dropDuplicates()\n", "stop_times_15km.show()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stop_times_15km.write.csv('data/lgpt_guys/stop_times_15km.csv', header=True, mode='overwrite')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3) Keep only services that run each day of the week" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "2322109" ] } ], "source": [ "stop_times_15km = spark.read.csv('data/lgpt_guys/stop_times_15km.csv', header=True)\n", "stop_times_15km.count()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "calendar = spark.read.csv(\"/data/sbb/timetables/csv/calendar/2019/05/14/calendar.txt\", header=True, sep = \",\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\n", "|service_id|monday|tuesday|wednesday|thursday|friday|saturday|sunday|start_date|end_date|\n", "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\n", "| TA+b0nx9| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b03bf| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0008| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxg| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b08k4| 1| 0| 0| 0| 0| 0| 0| 20181209|20191214|\n", "| TA+b06hs| 0| 0| 0| 0| 1| 0| 0| 20181209|20191214|\n", "| TA+b09de| 0| 0| 0| 0| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxn| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b05qx| 1| 1| 1| 0| 0| 0| 0| 20181209|20191214|\n", "| TA+b0nxa| 0| 0| 0| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b05k1| 1| 0| 0| 0| 0| 0| 0| 20181209|20191214|\n", "| TA+b01pq| 0| 0| 0| 0| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxb| 0| 0| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b04l2| 0| 1| 0| 0| 0| 0| 0| 20181209|20191214|\n", "| TA+b063g| 1| 0| 0| 0| 0| 0| 0| 20181209|20191214|\n", "| TA+b08xi| 1| 0| 0| 0| 0| 0| 0| 20181209|20191214|\n", "| TA+b0nxd| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxe| 0| 0| 0| 0| 0| 1| 1| 20181209|20191214|\n", "| TA+b0nxf| 0| 0| 0| 0| 0| 1| 1| 20181209|20191214|\n", "| TA+b08zi| 0| 0| 0| 0| 0| 0| 1| 20181209|20191214|\n", "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\n", "only showing top 20 rows" ] } ], "source": [ "calendar.show()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\n", "|service_id|monday|tuesday|wednesday|thursday|friday|saturday|sunday|start_date|end_date|\n", "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\n", "| TA+b0nx9| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b03bf| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0008| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxg| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxn| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxd| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxh| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxi| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxl| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0f63| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0f6a| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0ap6| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b03c1| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nke| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b09su| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b00bo| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxc| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxq| 1| 1| 1| 1| 1| 1| 1| 20181209|20191214|\n", "| TA+b0nuo| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "| TA+b0nxv| 1| 1| 1| 1| 1| 0| 0| 20181209|20191214|\n", "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\n", "only showing top 20 rows" ] } ], "source": [ "calendar_business_days = calendar.filter((calendar.monday==1) & \\\n", " (calendar.tuesday==1) & \\\n", " (calendar.wednesday==1) & \\\n", " (calendar.thursday==1) & \\\n", " (calendar.friday==1))\n", "calendar_business_days.show()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+----------+--------------------+------------------+---------------+------------+\n", "| route_id|service_id| trip_id| trip_headsign|trip_short_name|direction_id|\n", "+-----------+----------+--------------------+------------------+---------------+------------+\n", "|1-1-C-j19-1| TA+b0001|5.TA.1-1-C-j19-1.3.R|Zofingen, Altachen| 108| 1|\n", "|1-1-C-j19-1| TA+b0001|7.TA.1-1-C-j19-1.3.R|Zofingen, Altachen| 112| 1|\n", "|1-1-C-j19-1| TA+b0001|9.TA.1-1-C-j19-1.3.R|Zofingen, Altachen| 116| 1|\n", "|1-1-C-j19-1| TA+b0001|11.TA.1-1-C-j19-1...|Zofingen, Altachen| 120| 1|\n", "|1-1-C-j19-1| TA+b0001|13.TA.1-1-C-j19-1...|Zofingen, Altachen| 124| 1|\n", "|1-1-C-j19-1| TA+b0001|15.TA.1-1-C-j19-1...|Zofingen, Altachen| 128| 1|\n", "|1-1-C-j19-1| TA+b0001|17.TA.1-1-C-j19-1...|Zofingen, Altachen| 132| 1|\n", "|1-1-C-j19-1| TA+b0001|18.TA.1-1-C-j19-1...|Zofingen, Altachen| 134| 1|\n", "|1-1-C-j19-1| TA+b0001|19.TA.1-1-C-j19-1...|Zofingen, Altachen| 136| 1|\n", "|1-1-C-j19-1| TA+b0001|20.TA.1-1-C-j19-1...|Zofingen, Altachen| 138| 1|\n", "|1-1-C-j19-1| TA+b0001|21.TA.1-1-C-j19-1...|Zofingen, Altachen| 140| 1|\n", "|1-1-C-j19-1| TA+b0001|22.TA.1-1-C-j19-1...|Zofingen, Altachen| 142| 1|\n", "|1-1-C-j19-1| TA+b0001|23.TA.1-1-C-j19-1...|Zofingen, Altachen| 144| 1|\n", "|1-1-C-j19-1| TA+b0001|24.TA.1-1-C-j19-1...|Zofingen, Altachen| 146| 1|\n", "|1-1-C-j19-1| TA+b0001|25.TA.1-1-C-j19-1...|Zofingen, Altachen| 148| 1|\n", "|1-1-C-j19-1| TA+b0001|26.TA.1-1-C-j19-1...|Zofingen, Altachen| 150| 1|\n", "|1-1-C-j19-1| TA+b0001|27.TA.1-1-C-j19-1...|Zofingen, Altachen| 152| 1|\n", "|1-1-C-j19-1| TA+b0001|30.TA.1-1-C-j19-1...|Zofingen, Altachen| 156| 1|\n", "|1-1-C-j19-1| TA+b0001|37.TA.1-1-C-j19-1...|Zofingen, Altachen| 168| 1|\n", "|1-1-C-j19-1| TA+b0001|38.TA.1-1-C-j19-1...|Zofingen, Altachen| 172| 1|\n", "+-----------+----------+--------------------+------------------+---------------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "trips = spark.read.csv(\"/data/sbb/timetables/csv/trips/2019/05/14/trips.txt\", header=True, sep = \",\")\n", "trips.show()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "1017413" ] } ], "source": [ "trips.count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Is there any useful information contained in `start_date` and `end_date` ?" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+----------+--------+\n", "|start_date|end_date|\n", "+----------+--------+\n", "| 20181209|20191214|\n", "+----------+--------+" ] } ], "source": [ "calendar_business_days.select(calendar_business_days.start_date, calendar_business_days.end_date).dropDuplicates().show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`start_date` and `end_date` will not provide us with useful information as their values are the same for all services." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+----------+\n", "|service_id|\n", "+----------+\n", "| TA+b0nx9|\n", "| TA+b03bf|\n", "| TA+b0008|\n", "| TA+b0nxg|\n", "| TA+b0nxn|\n", "| TA+b0nxd|\n", "| TA+b0nxh|\n", "| TA+b0nxi|\n", "| TA+b0nxl|\n", "| TA+b0f63|\n", "| TA+b0f6a|\n", "| TA+b0ap6|\n", "| TA+b03c1|\n", "| TA+b0nke|\n", "| TA+b09su|\n", "| TA+b00bo|\n", "| TA+b0nxc|\n", "| TA+b0nxq|\n", "| TA+b0nuo|\n", "| TA+b0nxv|\n", "+----------+\n", "only showing top 20 rows" ] } ], "source": [ "calendar_business_days_for_join = calendar_business_days.select(calendar_business_days.service_id) \n", "calendar_business_days_for_join.show()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+----------+--------------+--------------------+--------------------+---------------+------------+\n", "|service_id| route_id| trip_id| trip_headsign|trip_short_name|direction_id|\n", "+----------+--------------+--------------------+--------------------+---------------+------------+\n", "| TA+b0b6f| 61-14-Y-j19-1|70.TA.61-14-Y-j19...| Betten Dorf| 6060| 0|\n", "| TA+b0b8s| 26-40-j19-1|655.TA.26-40-j19-...|Zürich, Bucheggplatz| 4329| 0|\n", "| TA+b0b90| 4-108-j19-1|185.TA.4-108-j19-...| Sissach, Bahnhof| 28008| 1|\n", "| TA+b0ba6| 24-571-j19-1|25.TA.24-571-j19-...| Zermatt, Spiss| 71142| 0|\n", "| TA+b0bkz| 25-1-A-j19-1|192.TA.25-1-A-j19...| Zug, Bahnhofplatz| 1517| 1|\n", "| TA+b0bpj| 24-142-j19-1|7.TA.24-142-j19-1...| Lax, Bahnhof| 525| 1|\n", "| TA+b0bpj| 24-142-j19-1|73.TA.24-142-j19-...| Lax, Bahnhof| 767| 1|\n", "| TA+b0bq1|61-382-Y-j19-1|67.TA.61-382-Y-j1...| Pfingstegg| 201| 0|\n", "| TA+b0bq4|61-527-Y-j19-1|321.TA.61-527-Y-j...| Pros da Darlux| 1| 0|\n", "| TA+b0bq4|61-528-Y-j19-1|41.TA.61-528-Y-j1...|Bergün/Bravuogn SBAD| 51| 0|\n", "| TA+b0bq4|61-528-Y-j19-1|293.TA.61-528-Y-j...|Bergün/Bravuogn SBAD| 51| 0|\n", "| TA+b0bq4|61-529-Y-j19-1|188.TA.61-529-Y-j...| Alp Darlux| 201| 0|\n", "| TA+b0bq4|61-558-Y-j19-1|40.TA.61-558-Y-j1...| Pros da Darlux| 251| 0|\n", "| TA+b0bq4|61-558-Y-j19-1|151.TA.61-558-Y-j...| Pros da Darlux| 251| 0|\n", "| TA+b0bq4|61-558-Y-j19-1|365.TA.61-558-Y-j...| Pros da Darlux| 251| 0|\n", "| TA+b0bq9| 61-46-Y-j19-1|34.TA.61-46-Y-j19...| Mittelallalin| 5101| 0|\n", "| TA+b0bq9| 61-46-Y-j19-1|141.TA.61-46-Y-j1...| Mittelallalin| 5101| 0|\n", "| TA+b0bq9| 61-47-Y-j19-1|686.TA.61-47-Y-j1...|Saas-Fee (Alpin E...| 3002| 0|\n", "| TA+b0bq9|61-575-Y-j19-1|596.TA.61-575-Y-j...| Felskinn| 3001| 0|\n", "| TA+b0bq9|61-575-Y-j19-1|676.TA.61-575-Y-j...| Felskinn| 3001| 0|\n", "+----------+--------------+--------------------+--------------------+---------------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "trips_business_week = trips.join(calendar_business_days_for_join, how=\"inner\", on = \"service_id\").dropDuplicates()\n", "trips_business_week.show()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "528368" ] } ], "source": [ "trips_business_week.count()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------+--------------------+--------------------+---------------+------------+\n", "| route_id| trip_id| trip_headsign|trip_short_name|direction_id|\n", "+--------------+--------------------+--------------------+---------------+------------+\n", "| 61-14-Y-j19-1|70.TA.61-14-Y-j19...| Betten Dorf| 6060| 0|\n", "| 26-40-j19-1|655.TA.26-40-j19-...|Zürich, Bucheggplatz| 4329| 0|\n", "| 4-108-j19-1|185.TA.4-108-j19-...| Sissach, Bahnhof| 28008| 1|\n", "| 24-571-j19-1|25.TA.24-571-j19-...| Zermatt, Spiss| 71142| 0|\n", "| 25-1-A-j19-1|192.TA.25-1-A-j19...| Zug, Bahnhofplatz| 1517| 1|\n", "| 24-142-j19-1|7.TA.24-142-j19-1...| Lax, Bahnhof| 525| 1|\n", "| 24-142-j19-1|73.TA.24-142-j19-...| Lax, Bahnhof| 767| 1|\n", "|61-382-Y-j19-1|67.TA.61-382-Y-j1...| Pfingstegg| 201| 0|\n", "|61-527-Y-j19-1|321.TA.61-527-Y-j...| Pros da Darlux| 1| 0|\n", "|61-528-Y-j19-1|41.TA.61-528-Y-j1...|Bergün/Bravuogn SBAD| 51| 0|\n", "|61-528-Y-j19-1|293.TA.61-528-Y-j...|Bergün/Bravuogn SBAD| 51| 0|\n", "|61-529-Y-j19-1|188.TA.61-529-Y-j...| Alp Darlux| 201| 0|\n", "|61-558-Y-j19-1|40.TA.61-558-Y-j1...| Pros da Darlux| 251| 0|\n", "|61-558-Y-j19-1|151.TA.61-558-Y-j...| Pros da Darlux| 251| 0|\n", "|61-558-Y-j19-1|365.TA.61-558-Y-j...| Pros da Darlux| 251| 0|\n", "| 61-46-Y-j19-1|34.TA.61-46-Y-j19...| Mittelallalin| 5101| 0|\n", "| 61-46-Y-j19-1|141.TA.61-46-Y-j1...| Mittelallalin| 5101| 0|\n", "| 61-47-Y-j19-1|686.TA.61-47-Y-j1...|Saas-Fee (Alpin E...| 3002| 0|\n", "|61-575-Y-j19-1|596.TA.61-575-Y-j...| Felskinn| 3001| 0|\n", "|61-575-Y-j19-1|676.TA.61-575-Y-j...| Felskinn| 3001| 0|\n", "+--------------+--------------------+--------------------+---------------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "trips_business_week_for_join = trips_business_week.drop('service_id')\n", "trips_business_week_for_join.show()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+------------+--------------------+---------------+------------+\n", "| trip_id| stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+------------+--------------------+---------------+------------+\n", "|1005.TA.26-131-j1...| 8573555| 16:19:00| 16:19:00| 5| 0| 0| 8573555| Horgen, Bergli|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...|8503855:0:F| 16:14:00| 16:14:00| 1| 0| 0| 8503855| Horgen, Bahnhof|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...| 8588984| 16:21:00| 16:21:00| 7| 0| 0| 8588984| Horgen, Gehren|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...| 8573554| 16:18:00| 16:18:00| 4| 0| 0| 8573554|Horgen Oberdorf, ...|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...| 8588985| 16:20:00| 16:20:00| 6| 0| 0| 8588985| Horgen, Heubach|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...| 8573553| 16:16:00| 16:16:00| 3| 0| 0| 8573553| Horgen, Stocker|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...| 8589111| 16:15:00| 16:15:00| 2| 0| 0| 8589111|Horgen, Gumelenst...|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|103.TA.26-925-j19...| 8576082| 07:38:00| 07:38:00| 20| 0| 0| 8576082| Meilen, Beugen|26-925-j19-1| Meilen, Bahnhof| 571| 0|\n", "|103.TA.26-925-j19...| 8576080| 07:42:00| 07:42:00| 21| 0| 0| 8576080| Meilen, Bahnhof|26-925-j19-1| Meilen, Bahnhof| 571| 0|\n", "|104.TA.26-733-j19...| 8587420| 07:40:00| 07:40:00| 6| 0| 0| 8587420| Kloten, Bahnhof|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8588553| 07:34:00| 07:34:00| 3| 0| 0| 8588553|Zürich Flughafen,...|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8580301| 07:33:00| 07:33:00| 2| 0| 0| 8580301|Zürich Flughafen,...|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...|8573205:0:D| 07:33:00| 07:33:00| 1| 0| 0| 8573205|Zürich Flughafen,...|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8580434| 07:41:00| 07:41:00| 7| 0| 0| 8580434|Kloten, Lindenstr...|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8573211| 07:36:00| 07:36:00| 4| 0| 0| 8573211|Kloten, Zum Wilde...|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8580433| 07:44:00| 07:44:00| 9| 0| 0| 8580433| Kloten, Graswinkel|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8590699| 07:37:00| 07:37:00| 5| 0| 0| 8590699| Kloten, Stadthaus|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|104.TA.26-733-j19...| 8576153| 07:42:00| 07:42:00| 8| 0| 0| 8576153| Kloten, Rankstrasse|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|1087.TA.26-5-B-j1...| 8591239| 15:57:00| 15:57:00| 10| 0| 0| 8591239| Zürich, Kunsthaus|26-5-B-j19-1|Zürich, Kirche Fl...| 3194| 1|\n", "|1087.TA.26-5-B-j1...| 8591303| 16:00:00| 16:00:00| 12| 0| 0| 8591303| Zürich, Platte|26-5-B-j19-1|Zürich, Kirche Fl...| 3194| 1|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+------------+--------------------+---------------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times_15km_business_week = stop_times_15km.join(trips_business_week_for_join, how=\"inner\", on = \"trip_id\").dropDuplicates()\n", "stop_times_15km_business_week.show()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stop_times_15km_business_week.write.csv('data/lgpt_guys/stop_times_15km_business_week.csv', header=True, mode='overwrite')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 4) Keeping only departure times between a certain time of the day (7am, 8pm)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+\n", "| trip_id| stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+\n", "|1.TA.26-925-j19-1...| 8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen| 26-925-j19-1| Meilen, Bahnhof| 280| 0|\n", "|1.TA.26-925-j19-1...| 8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof| 26-925-j19-1| Meilen, Bahnhof| 280| 0|\n", "|1014.TA.26-70-A-j...| 8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591210| 12:03:00| 12:03:00| 11| 0| 0| 8591210| Zürich, Im Hüsli|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591154| 11:59:00| 11:59:00| 8| 0| 0| 8591154|Zürich, Frymannst...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591370| 12:04:00| 12:04:00| 12| 0| 0| 8591370|Zürich, Sihlweids...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591270| 12:02:00| 12:02:00| 10| 0| 0| 8591270| Zürich, Marbachweg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591081| 11:53:00| 11:53:00| 2| 0| 0| 8591081|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...| 8591278| 12:05:00| 12:05:00| 13| 0| 0| 8591278|Zürich, Mittellei...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|102.TA.26-765-j19...| 8576154| 19:21:00| 19:21:00| 14| 0| 0| 8576154| Kloten, Oberfeld| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...| 8576158| 19:17:00| 19:17:00| 10| 0| 0| 8576158|Bassersdorf, Talg...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...| 8576152| 19:24:00| 19:24:00| 16| 0| 0| 8576152| Kloten, Kirchgasse| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...|8573205:0:F| 19:29:00| 19:29:00| 20| 0| 0| 8573205|Zürich Flughafen,...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...| 8588316| 19:11:00| 19:11:00| 6| 0| 0| 8588316|Bassersdorf, Diet...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times_15km_business_week = spark.read.csv('data/lgpt_guys/stop_times_15km_business_week.csv', header=True)\n", "stop_times_15km_business_week.show()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "398630" ] } ], "source": [ "stop_times_15km_business_week.count()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "| trip_id| stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "|1.TA.26-925-j19-1...| 8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1.TA.26-925-j19-1...| 8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1014.TA.26-70-A-j...| 8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591210| 12:03:00| 12:03:00| 11| 0| 0| 8591210| Zürich, Im Hüsli|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591154| 11:59:00| 11:59:00| 8| 0| 0| 8591154|Zürich, Frymannst...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591370| 12:04:00| 12:04:00| 12| 0| 0| 8591370|Zürich, Sihlweids...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591270| 12:02:00| 12:02:00| 10| 0| 0| 8591270| Zürich, Marbachweg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591081| 11:53:00| 11:53:00| 2| 0| 0| 8591081|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591278| 12:05:00| 12:05:00| 13| 0| 0| 8591278|Zürich, Mittellei...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|102.TA.26-765-j19...| 8576154| 19:21:00| 19:21:00| 14| 0| 0| 8576154| Kloten, Oberfeld| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8576158| 19:17:00| 19:17:00| 10| 0| 0| 8576158|Bassersdorf, Talg...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8576152| 19:24:00| 19:24:00| 16| 0| 0| 8576152| Kloten, Kirchgasse| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8573205:0:F| 19:29:00| 19:29:00| 20| 0| 0| 8573205|Zürich Flughafen,...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8588316| 19:11:00| 19:11:00| 6| 0| 0| 8588316|Bassersdorf, Diet...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times_15km_business_week = stop_times_15km_business_week.withColumn(\"departure_hour\", stop_times_15km_business_week.departure_time.substr(0, 2).cast('int'))\n", "stop_times_15km_business_week.show()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "| trip_id| stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "|1.TA.26-925-j19-1...| 8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1.TA.26-925-j19-1...| 8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1014.TA.26-70-A-j...| 8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591210| 12:03:00| 12:03:00| 11| 0| 0| 8591210| Zürich, Im Hüsli|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591154| 11:59:00| 11:59:00| 8| 0| 0| 8591154|Zürich, Frymannst...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591370| 12:04:00| 12:04:00| 12| 0| 0| 8591370|Zürich, Sihlweids...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591270| 12:02:00| 12:02:00| 10| 0| 0| 8591270| Zürich, Marbachweg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591081| 11:53:00| 11:53:00| 2| 0| 0| 8591081|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591278| 12:05:00| 12:05:00| 13| 0| 0| 8591278|Zürich, Mittellei...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|102.TA.26-765-j19...| 8576154| 19:21:00| 19:21:00| 14| 0| 0| 8576154| Kloten, Oberfeld| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8576158| 19:17:00| 19:17:00| 10| 0| 0| 8576158|Bassersdorf, Talg...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8576152| 19:24:00| 19:24:00| 16| 0| 0| 8576152| Kloten, Kirchgasse| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8573205:0:F| 19:29:00| 19:29:00| 20| 0| 0| 8573205|Zürich Flughafen,...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8588316| 19:11:00| 19:11:00| 6| 0| 0| 8588316|Bassersdorf, Diet...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "only showing top 20 rows" ] } ], "source": [ "departure_earliest = 7\n", "departure_latest = 19\n", "stop_times_15km_business_week_standard_hours = stop_times_15km_business_week.filter((stop_times_15km_business_week.departure_hour>=departure_earliest) & \\\n", " (stop_times_15km_business_week.departure_hour<= departure_latest))\n", "stop_times_15km_business_week_standard_hours.show()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# intermediate saving point\n", "stop_times_15km_business_week_standard_hours.write.csv('data/lgpt_guys/stop_times_15km_business_week_standard_hours.csv', header = True, mode=\"overwrite\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 5) Order stop_times as to reconstruct routes for RAPTOR" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building a list of unique trips according to 1) the stop sequence and 2) the departure time sequence" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "304085" ] } ], "source": [ "# we start fresh from here, where stop_times is in fact stop_times_15km_business_week_standard_hours loaded from the server\n", "stop_times = spark.read.csv('data/lgpt_guys/stop_times_15km_business_week_standard_hours.csv', header = True)\n", "stop_times.count()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "| trip_id| stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "|1.TA.26-925-j19-1...| 8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1.TA.26-925-j19-1...| 8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1014.TA.26-70-A-j...| 8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591210| 12:03:00| 12:03:00| 11| 0| 0| 8591210| Zürich, Im Hüsli|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591154| 11:59:00| 11:59:00| 8| 0| 0| 8591154|Zürich, Frymannst...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591370| 12:04:00| 12:04:00| 12| 0| 0| 8591370|Zürich, Sihlweids...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591270| 12:02:00| 12:02:00| 10| 0| 0| 8591270| Zürich, Marbachweg|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...| 8591081| 11:53:00| 11:53:00| 2| 0| 0| 8591081|Zürich Wollishofe...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...| 8591278| 12:05:00| 12:05:00| 13| 0| 0| 8591278|Zürich, Mittellei...|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|102.TA.26-765-j19...| 8576154| 19:21:00| 19:21:00| 14| 0| 0| 8576154| Kloten, Oberfeld| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8576158| 19:17:00| 19:17:00| 10| 0| 0| 8576158|Bassersdorf, Talg...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8576152| 19:24:00| 19:24:00| 16| 0| 0| 8576152| Kloten, Kirchgasse| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8573205:0:F| 19:29:00| 19:29:00| 20| 0| 0| 8573205|Zürich Flughafen,...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...| 8588316| 19:11:00| 19:11:00| 6| 0| 0| 8588316|Bassersdorf, Diet...| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times.show()" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-----------+--------------------+---------------+------------+--------------+\n", "| trip_id|stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-----------+--------------------+---------------+------------+--------------+\n", "|1.TA.1-231-j19-1.1.H|8572747| 09:37:00| 09:37:00| 1| 0| 0| 8572747|Bremgarten AG, Ba...|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8582462| 09:38:00| 09:38:00| 3| 0| 0| 8582462|Bremgarten AG, Ze...|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8572600| 09:39:00| 09:39:00| 4| 0| 0| 8572600| Zufikon, Emaus|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8572601| 09:39:00| 09:39:00| 5| 0| 0| 8572601| Zufikon, Algier|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8502553| 09:43:00| 09:43:00| 6| 0| 0| 8502553|Unterlunkhofen, B...|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8572602| 09:45:00| 09:45:00| 7| 0| 0| 8572602|Oberlunkhofen, Ke...|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8502955| 09:46:00| 09:47:00| 8| 0| 0| 8502955| Oberlunkhofen, Post|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8573722| 09:48:00| 09:48:00| 9| 0| 0| 8573722|Oberlunkhofen, Ob...|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8573721| 09:50:00| 09:50:00| 10| 0| 0| 8573721|Oberlunkhofen, Wa...|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8503598| 09:53:00| 09:53:00| 11| 0| 0| 8503598| Arni AG, Dorf|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8573720| 09:55:00| 09:59:00| 12| 0| 0| 8573720| Arni AG, Stockacker|1-231-j19-1| Jonen, Post| 23127| 0| 9|\n", "|1.TA.1-231-j19-1.1.H|8503598| 10:00:00| 10:00:00| 13| 0| 0| 8503598| Arni AG, Dorf|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "|1.TA.1-231-j19-1.1.H|8573721| 10:02:00| 10:02:00| 14| 0| 0| 8573721|Oberlunkhofen, Wa...|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "|1.TA.1-231-j19-1.1.H|8573722| 10:03:00| 10:03:00| 15| 0| 0| 8573722|Oberlunkhofen, Ob...|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "|1.TA.1-231-j19-1.1.H|8573723| 10:04:00| 10:04:00| 16| 0| 0| 8573723|Oberlunkhofen, Do...|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "|1.TA.1-231-j19-1.1.H|8583071| 10:05:00| 10:05:00| 17| 0| 0| 8583071| Jonen, Radmühle|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "|1.TA.1-231-j19-1.1.H|8572603| 10:06:00| 10:06:00| 18| 0| 0| 8572603| Jonen, Käppeli|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "|1.TA.1-231-j19-1.1.H|8502879| 10:07:00| 10:07:00| 19| 0| 0| 8502879| Jonen, Post|1-231-j19-1| Jonen, Post| 23127| 0| 10|\n", "| 1.TA.1-44-j19-1.1.R|8590275| 08:31:00| 08:31:00| 1| 0| 0| 8590275| Spreitenbach, IKEA| 1-44-j19-1|Spreitenbach, Sho...| 2001| 1| 8|\n", "| 1.TA.1-44-j19-1.1.R|8591891| 08:34:00| 08:34:00| 2| 0| 0| 8591891|Spreitenbach, Alt...| 1-44-j19-1|Spreitenbach, Sho...| 2001| 1| 8|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-----------+--------------------+---------------+------------+--------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times = stop_times.sort(stop_times.trip_id, stop_times.stop_sequence.cast('int'))\n", "stop_times.show()" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from pyspark.sql.window import Window\n", "w= (\n", " Window.partitionBy(\"trip_id\")\n", " .orderBy(stop_times.stop_sequence.cast('int'))\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This step is a bit technical. We aim at identifying trips that are identical, although they may bear a different `trip_id`. Indeed, we used data from services running every day of a standard business week. But we do not take days of the week into account, only departure and arrival **hours**. Therefore, we must find a way to identify and merge identical trips in terms of stops served and arrival and departure times. \n", "\n", "To do so, we use window functions on each trip to build a stop sequence and a list of departure times. When departure times are identical, arrival times are considered identical." ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-------------------------+---------------+--------------+-------------+--------------+------------------------------------------------------------------------------------------------------------------------------+\n", "|trip_id |stop_id_general|departure_time|stop_sequence|departure_hour|all_stops |\n", "+-------------------------+---------------+--------------+-------------+--------------+------------------------------------------------------------------------------------------------------------------------------+\n", "|1005.TA.26-131-j19-1.9.H |8503855 |16:14:00 |1 |16 |[8503855] |\n", "|1005.TA.26-131-j19-1.9.H |8589111 |16:15:00 |2 |16 |[8503855, 8589111] |\n", "|1005.TA.26-131-j19-1.9.H |8573553 |16:16:00 |3 |16 |[8503855, 8589111, 8573553] |\n", "|1005.TA.26-131-j19-1.9.H |8573554 |16:18:00 |4 |16 |[8503855, 8589111, 8573553, 8573554] |\n", "|1005.TA.26-131-j19-1.9.H |8573555 |16:19:00 |5 |16 |[8503855, 8589111, 8573553, 8573554, 8573555] |\n", "|1005.TA.26-131-j19-1.9.H |8588985 |16:20:00 |6 |16 |[8503855, 8589111, 8573553, 8573554, 8573555, 8588985] |\n", "|1005.TA.26-131-j19-1.9.H |8588984 |16:21:00 |7 |16 |[8503855, 8589111, 8573553, 8573554, 8573555, 8588985, 8588984] |\n", "|103.TA.26-925-j19-1.4.H |8576082 |07:38:00 |20 |7 |[8576082] |\n", "|103.TA.26-925-j19-1.4.H |8576080 |07:42:00 |21 |7 |[8576082, 8576080] |\n", "|104.TA.26-733-j19-1.2.R |8573205 |07:33:00 |1 |7 |[8573205] |\n", "|104.TA.26-733-j19-1.2.R |8580301 |07:33:00 |2 |7 |[8573205, 8580301] |\n", "|104.TA.26-733-j19-1.2.R |8588553 |07:34:00 |3 |7 |[8573205, 8580301, 8588553] |\n", "|104.TA.26-733-j19-1.2.R |8573211 |07:36:00 |4 |7 |[8573205, 8580301, 8588553, 8573211] |\n", "|104.TA.26-733-j19-1.2.R |8590699 |07:37:00 |5 |7 |[8573205, 8580301, 8588553, 8573211, 8590699] |\n", "|104.TA.26-733-j19-1.2.R |8587420 |07:40:00 |6 |7 |[8573205, 8580301, 8588553, 8573211, 8590699, 8587420] |\n", "|104.TA.26-733-j19-1.2.R |8580434 |07:41:00 |7 |7 |[8573205, 8580301, 8588553, 8573211, 8590699, 8587420, 8580434] |\n", "|104.TA.26-733-j19-1.2.R |8576153 |07:42:00 |8 |7 |[8573205, 8580301, 8588553, 8573211, 8590699, 8587420, 8580434, 8576153] |\n", "|104.TA.26-733-j19-1.2.R |8580433 |07:44:00 |9 |7 |[8573205, 8580301, 8588553, 8573211, 8590699, 8587420, 8580434, 8576153, 8580433] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591245 |15:42:00 |1 |15 |[8591245] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591329 |15:43:00 |2 |15 |[8591245, 8591329] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591366 |15:45:00 |3 |15 |[8591245, 8591329, 8591366] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591415 |15:46:00 |4 |15 |[8591245, 8591329, 8591366, 8591415] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591059 |15:47:00 |5 |15 |[8591245, 8591329, 8591366, 8591415, 8591059] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591058 |15:49:00 |6 |15 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591317 |15:51:00 |7 |15 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591105 |15:53:00 |8 |15 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105] |\n", "|1087.TA.26-5-B-j19-1.23.R|8576193 |15:55:00 |9 |15 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591239 |15:57:00 |10 |15 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591220 |15:58:00 |11 |15 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591303 |16:00:00 |12 |16 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591412 |16:02:00 |13 |16 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303, 8591412] |\n", "|1087.TA.26-5-B-j19-1.23.R|8591230 |16:04:00 |14 |16 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303, 8591412, 8591230]|\n", "|109.TA.1-1-E-j19-1.12.R |8578679 |11:04:00 |1 |11 |[8578679] |\n", "|109.TA.1-1-E-j19-1.12.R |8590314 |11:05:00 |2 |11 |[8578679, 8590314] |\n", "|109.TA.1-1-E-j19-1.12.R |8590317 |11:06:00 |3 |11 |[8578679, 8590314, 8590317] |\n", "|109.TA.79-24-j19-1.1.R |8503500 |16:50:00 |1 |16 |[8503500] |\n", "|109.TA.79-24-j19-1.1.R |8503499 |16:53:00 |2 |16 |[8503500, 8503499] |\n", "|1099.TA.26-142-j19-1.2.R |8590815 |17:31:00 |1 |17 |[8590815] |\n", "|1099.TA.26-142-j19-1.2.R |8590817 |17:32:00 |2 |17 |[8590815, 8590817] |\n", "|1099.TA.26-142-j19-1.2.R |8590812 |17:33:00 |3 |17 |[8590815, 8590817, 8590812] |\n", "|1099.TA.26-142-j19-1.2.R |8590825 |17:35:00 |4 |17 |[8590815, 8590817, 8590812, 8590825] |\n", "|1099.TA.26-142-j19-1.2.R |8590830 |17:36:00 |5 |17 |[8590815, 8590817, 8590812, 8590825, 8590830] |\n", "|1099.TA.26-142-j19-1.2.R |8590818 |17:37:00 |6 |17 |[8590815, 8590817, 8590812, 8590825, 8590830, 8590818] |\n", "|1099.TA.26-142-j19-1.2.R |8573167 |17:40:00 |7 |17 |[8590815, 8590817, 8590812, 8590825, 8590830, 8590818, 8573167] |\n", "|11.TA.1-444-j19-1.1.H |8572747 |18:35:00 |2 |18 |[8572747] |\n", "|11.TA.1-444-j19-1.1.H |8580847 |18:36:00 |3 |18 |[8572747, 8580847] |\n", "|11.TA.1-444-j19-1.1.H |8581346 |18:41:00 |4 |18 |[8572747, 8580847, 8581346] |\n", "|11.TA.1-444-j19-1.1.H |8502894 |18:42:00 |5 |18 |[8572747, 8580847, 8581346, 8502894] |\n", "|11.TA.1-444-j19-1.1.H |8502979 |18:43:00 |6 |18 |[8572747, 8580847, 8581346, 8502894, 8502979] |\n", "|11.TA.1-444-j19-1.1.H |8572596 |18:44:00 |7 |18 |[8572747, 8580847, 8581346, 8502894, 8502979, 8572596] |\n", "|11.TA.1-444-j19-1.1.H |8591365 |18:59:00 |8 |18 |[8572747, 8580847, 8581346, 8502894, 8502979, 8572596, 8591365] |\n", "|11.TA.1-444-j19-1.1.H |8591366 |19:01:00 |9 |19 |[8572747, 8580847, 8581346, 8502894, 8502979, 8572596, 8591365, 8591366] |\n", "|11.TA.1-444-j19-1.1.H |8591059 |19:03:00 |10 |19 |[8572747, 8580847, 8581346, 8502894, 8502979, 8572596, 8591365, 8591366, 8591059] |\n", "|111.TA.79-736-j19-1.5.H |8591031 |18:39:00 |1 |18 |[8591031] |\n", "|111.TA.79-736-j19-1.5.H |8588553 |18:41:00 |2 |18 |[8591031, 8588553] |\n", "|111.TA.79-736-j19-1.5.H |8580301 |18:42:00 |3 |18 |[8591031, 8588553, 8580301] |\n", "|111.TA.79-736-j19-1.5.H |8573205 |18:44:00 |4 |18 |[8591031, 8588553, 8580301, 8573205] |\n", "|111.TA.79-736-j19-1.5.H |8573213 |18:45:00 |5 |18 |[8591031, 8588553, 8580301, 8573205, 8573213] |\n", "|111.TA.79-736-j19-1.5.H |8587799 |18:46:00 |6 |18 |[8591031, 8588553, 8580301, 8573205, 8573213, 8587799] |\n", "|111.TA.79-736-j19-1.5.H |8591032 |18:49:00 |7 |18 |[8591031, 8588553, 8580301, 8573205, 8573213, 8587799, 8591032] |\n", "|111.TA.79-736-j19-1.5.H |8593523 |18:51:00 |8 |18 |[8591031, 8588553, 8580301, 8573205, 8573213, 8587799, 8591032, 8593523] |\n", "|1139.TA.26-156-j19-1.4.R |8573167 |11:57:00 |1 |11 |[8573167] |\n", "|1139.TA.26-156-j19-1.4.R |8590824 |11:58:00 |2 |11 |[8573167, 8590824] |\n", "|1139.TA.26-156-j19-1.4.R |8590822 |11:59:00 |3 |11 |[8573167, 8590824, 8590822] |\n", "|1139.TA.26-156-j19-1.4.R |8590811 |12:00:00 |4 |12 |[8573167, 8590824, 8590822, 8590811] |\n", "|1139.TA.26-156-j19-1.4.R |8590826 |12:01:00 |5 |12 |[8573167, 8590824, 8590822, 8590811, 8590826] |\n", "|1139.TA.26-156-j19-1.4.R |8595406 |12:02:00 |6 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406] |\n", "|1139.TA.26-156-j19-1.4.R |8590828 |12:03:00 |7 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828] |\n", "|1139.TA.26-156-j19-1.4.R |8590780 |12:04:00 |8 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780] |\n", "|1139.TA.26-156-j19-1.4.R |8590779 |12:06:00 |9 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780, 8590779] |\n", "|1139.TA.26-156-j19-1.4.R |8590775 |12:06:00 |10 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780, 8590779, 8590775] |\n", "|1139.TA.26-156-j19-1.4.R |8590777 |12:07:00 |11 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780, 8590779, 8590775, 8590777] |\n", "|1139.TA.26-156-j19-1.4.R |8590482 |12:09:00 |12 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780, 8590779, 8590775, 8590777, 8590482] |\n", "|1139.TA.26-156-j19-1.4.R |8590464 |12:11:00 |13 |12 |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780, 8590779, 8590775, 8590777, 8590482, 8590464] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591245 |10:35:00 |1 |10 |[8591245] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591329 |10:36:00 |2 |10 |[8591245, 8591329] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591366 |10:37:00 |3 |10 |[8591245, 8591329, 8591366] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591415 |10:39:00 |4 |10 |[8591245, 8591329, 8591366, 8591415] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591059 |10:40:00 |5 |10 |[8591245, 8591329, 8591366, 8591415, 8591059] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591058 |10:41:00 |6 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591317 |10:43:00 |7 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591105 |10:45:00 |8 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105] |\n", "|1141.TA.26-5-B-j19-1.23.R|8576193 |10:48:00 |9 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591239 |10:50:00 |10 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591220 |10:51:00 |11 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591303 |10:53:00 |12 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591412 |10:55:00 |13 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303, 8591412] |\n", "|1141.TA.26-5-B-j19-1.23.R|8591230 |10:56:00 |14 |10 |[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303, 8591412, 8591230]|\n", "|1158.TA.26-69-j19-1.4.H |8591122 |14:30:00 |1 |14 |[8591122] |\n", "|1158.TA.26-69-j19-1.4.H |8591201 |14:31:00 |2 |14 |[8591122, 8591201] |\n", "|1158.TA.26-69-j19-1.4.H |8591213 |14:32:00 |3 |14 |[8591122, 8591201, 8591213] |\n", "|1158.TA.26-69-j19-1.4.H |8591416 |14:33:00 |4 |14 |[8591122, 8591201, 8591213, 8591416] |\n", "|1158.TA.26-69-j19-1.4.H |8591302 |14:34:00 |5 |14 |[8591122, 8591201, 8591213, 8591416, 8591302] |\n", "|1158.TA.26-69-j19-1.4.H |8591419 |14:35:00 |6 |14 |[8591122, 8591201, 8591213, 8591416, 8591302, 8591419] |\n", "|1158.TA.26-69-j19-1.4.H |8591425 |14:36:00 |7 |14 |[8591122, 8591201, 8591213, 8591416, 8591302, 8591419, 8591425] |\n", "|1158.TA.26-69-j19-1.4.H |8591101 |14:38:00 |8 |14 |[8591122, 8591201, 8591213, 8591416, 8591302, 8591419, 8591425, 8591101] |\n", "|1158.TA.26-69-j19-1.4.H |8591276 |14:41:00 |9 |14 |[8591122, 8591201, 8591213, 8591416, 8591302, 8591419, 8591425, 8591101, 8591276] |\n", "|1164.TA.26-5-B-j19-1.23.R|8591245 |19:58:00 |1 |19 |[8591245] |\n", "|1164.TA.26-5-B-j19-1.23.R|8591329 |19:59:00 |2 |19 |[8591245, 8591329] |\n", "|1186.TA.26-69-j19-1.4.H |8591122 |11:00:00 |1 |11 |[8591122] |\n", "+-------------------------+---------------+--------------+-------------+--------------+------------------------------------------------------------------------------------------------------------------------------+\n", "only showing top 100 rows" ] } ], "source": [ "# code from https://stackoverflow.com/questions/56763946/concat-multiple-string-rows-for-each-unique-id-by-a-particular-order\n", "from pyspark.sql import functions as F\n", "stop_times.withColumn(\"all_stops\",F.collect_list(\"stop_id_general\").over(w))\\\n", ".withColumn(\"all_departures\",F.collect_list(\"departure_time\").over(w))\\\n", ".select(F.col('trip_id'), F.col('stop_id_general'), F.col('departure_time'), \n", " F.col('stop_sequence'), F.col('departure_hour'), F.col('all_stops'))\\\n", ".show(100, 0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We successfully built incremental lists of departure times and stop_id sequences. We now need to select for the longest list for each `trip_id`. The `groupBy` line below does exactly that." ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-------------------------+------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+\n", "|trip_id |all_stops |all_departures |all_arrivals |\n", "+-------------------------+------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+\n", "|1005.TA.26-131-j19-1.9.H |[8503855, 8589111, 8573553, 8573554, 8573555, 8588985, 8588984] |[16:14:00, 16:15:00, 16:16:00, 16:18:00, 16:19:00, 16:20:00, 16:21:00] |[16:14:00, 16:15:00, 16:16:00, 16:18:00, 16:19:00, 16:20:00, 16:21:00] |\n", "|103.TA.26-925-j19-1.4.H |[8576082, 8576080] |[07:38:00, 07:42:00] |[07:38:00, 07:42:00] |\n", "|104.TA.26-733-j19-1.2.R |[8573205, 8580301, 8588553, 8573211, 8590699, 8587420, 8580434, 8576153, 8580433] |[07:33:00, 07:33:00, 07:34:00, 07:36:00, 07:37:00, 07:40:00, 07:41:00, 07:42:00, 07:44:00] |[07:33:00, 07:33:00, 07:34:00, 07:36:00, 07:37:00, 07:40:00, 07:41:00, 07:42:00, 07:44:00] |\n", "|1087.TA.26-5-B-j19-1.23.R|[8591245, 8591329, 8591366, 8591415, 8591059, 8591058, 8591317, 8591105, 8576193, 8591239, 8591220, 8591303, 8591412, 8591230]|[15:42:00, 15:43:00, 15:45:00, 15:46:00, 15:47:00, 15:49:00, 15:51:00, 15:53:00, 15:55:00, 15:57:00, 15:58:00, 16:00:00, 16:02:00, 16:04:00]|[15:42:00, 15:43:00, 15:45:00, 15:46:00, 15:47:00, 15:49:00, 15:51:00, 15:53:00, 15:55:00, 15:57:00, 15:58:00, 16:00:00, 16:02:00, 16:04:00]|\n", "|109.TA.1-1-E-j19-1.12.R |[8578679, 8590314, 8590317] |[11:04:00, 11:05:00, 11:06:00] |[11:04:00, 11:05:00, 11:06:00] |\n", "|109.TA.79-24-j19-1.1.R |[8503500, 8503499] |[16:50:00, 16:53:00] |[16:50:00, 16:53:00] |\n", "|1099.TA.26-142-j19-1.2.R |[8590815, 8590817, 8590812, 8590825, 8590830, 8590818, 8573167] |[17:31:00, 17:32:00, 17:33:00, 17:35:00, 17:36:00, 17:37:00, 17:40:00] |[17:31:00, 17:32:00, 17:33:00, 17:35:00, 17:36:00, 17:37:00, 17:40:00] |\n", "|11.TA.1-444-j19-1.1.H |[8572747, 8580847, 8581346, 8502894, 8502979, 8572596, 8591365, 8591366, 8591059] |[18:35:00, 18:36:00, 18:41:00, 18:42:00, 18:43:00, 18:44:00, 18:59:00, 19:01:00, 19:03:00] |[18:35:00, 18:36:00, 18:41:00, 18:42:00, 18:43:00, 18:44:00, 18:59:00, 19:01:00, 19:03:00] |\n", "|111.TA.79-736-j19-1.5.H |[8591031, 8588553, 8580301, 8573205, 8573213, 8587799, 8591032, 8593523] |[18:39:00, 18:41:00, 18:42:00, 18:44:00, 18:45:00, 18:46:00, 18:49:00, 18:51:00] |[18:39:00, 18:41:00, 18:42:00, 18:43:00, 18:45:00, 18:46:00, 18:49:00, 18:51:00] |\n", "|1139.TA.26-156-j19-1.4.R |[8573167, 8590824, 8590822, 8590811, 8590826, 8595406, 8590828, 8590780, 8590779, 8590775, 8590777, 8590482, 8590464] |[11:57:00, 11:58:00, 11:59:00, 12:00:00, 12:01:00, 12:02:00, 12:03:00, 12:04:00, 12:06:00, 12:06:00, 12:07:00, 12:09:00, 12:11:00] |[11:57:00, 11:58:00, 11:59:00, 12:00:00, 12:01:00, 12:02:00, 12:03:00, 12:04:00, 12:06:00, 12:06:00, 12:07:00, 12:09:00, 12:11:00] |\n", "+-------------------------+------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+\n", "only showing top 10 rows" ] } ], "source": [ "trips_with_duplicates= stop_times.withColumn(\"all_stops\",F.collect_list(\"stop_id_general\").over(w))\\\n", ".withColumn(\"all_departures\",F.collect_list(\"departure_time\").over(w))\\\n", ".withColumn(\"all_arrivals\",F.collect_list(\"arrival_time\").over(w))\\\n", ".groupBy(\"trip_id\")\\\n", ".agg(F.max(\"all_stops\").alias(\"all_stops\"), F.max(\"all_departures\").alias(\"all_departures\"), F.max(\"all_arrivals\").alias(\"all_arrivals\"))\\\n", "\n", "trips_with_duplicates.show(10, 0)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "25127" ] } ], "source": [ "trips_with_duplicates.count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Are there many trips with a single stop ?" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+---------+--------------+----------+\n", "| trip_id|all_stops|all_departures|stop_count|\n", "+--------------------+---------+--------------+----------+\n", "|366.TA.11-3-j19-1...|[8503000]| [15:23:00]| 1|\n", "|457.TA.26-24-j19-...|[8502208]| [16:45:00]| 1|\n", "|99.TA.1-321-j19-1...|[8502750]| [16:07:00]| 1|\n", "|31.TA.80-158-Y-j1...|[8503000]| [14:38:00]| 1|\n", "|423.TA.1-36-j19-1...|[8503000]| [09:36:00]| 1|\n", "|808.TA.26-24-j19-...|[8502208]| [17:15:00]| 1|\n", "|1.TA.20-E03-j19-1...|[8596126]| [19:15:00]| 1|\n", "|103.TA.1-321-j19-...|[8502750]| [18:07:00]| 1|\n", "|123.TA.1-321-j19-...|[8502750]| [12:07:00]| 1|\n", "|141.TA.20-2-j19-1...|[8503000]| [08:10:00]| 1|\n", "|17.TA.17-4-j19-1.5.H|[8503000]| [12:37:00]| 1|\n", "|17.TA.80-158-Y-j1...|[8503000]| [10:38:00]| 1|\n", "|346.TA.1-37-j19-1...|[8503000]| [11:08:00]| 1|\n", "|399.TA.11-3-j19-1...|[8503000]| [11:37:00]| 1|\n", "| 4.TA.17-4-j19-1.4.H|[8503000]| [18:37:00]| 1|\n", "|450.TA.1-16-j19-1...|[8503000]| [15:54:00]| 1|\n", "|611.TA.26-8-A-j19...|[8503204]| [07:00:00]| 1|\n", "|178.TA.20-2-j19-1...|[8503000]| [19:18:00]| 1|\n", "|410.TA.26-24-j19-...|[8502208]| [10:45:00]| 1|\n", "|1.TA.57-2-Y-j19-1...|[8503000]| [09:34:00]| 1|\n", "+--------------------+---------+--------------+----------+\n", "only showing top 20 rows" ] } ], "source": [ "from pyspark.sql.types import IntegerType\n", "slen = udf(lambda s: len(s), IntegerType())\n", "\n", "trips_with_duplicates.withColumn(\"stop_count\", slen(trips_with_duplicates.all_stops)).filter(F.col('stop_count')==1).show()" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "714" ] } ], "source": [ "trips_with_duplicates.withColumn(\"stop_count\", slen(trips_with_duplicates.all_stops)).filter(F.col('stop_count')==1).count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How many trips share exactly the same departure **and** arrival times at all stops ?" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+\n", "| trip_id| all_stops| all_departures| all_arrivals|\n", "+--------------------+--------------------+--------------------+--------------------+\n", "|382.TA.11-3-j19-1...| [8503000]| [15:53:00]| [15:53:00]|\n", "|87.TA.6-8-j19-1.64.R| [8503016, 8503000]|[08:46:00, 09:02:00]|[08:44:00, 08:55:00]|\n", "|32.TA.79-10-B-j19...|[8503054, 8503053...|[17:57:00, 17:59:...|[17:57:00, 17:59:...|\n", "|448.TA.26-LAF-j19...| [8503082, 8503081]|[19:20:00, 19:25:00]|[19:20:00, 19:25:00]|\n", "|294.TA.26-5-A-j19...|[8503125, 8503003...|[17:21:00, 17:32:...|[17:20:00, 17:32:...|\n", "|996.TA.26-12-j19-...|[8503147, 8503003...|[14:34:00, 14:39:...|[14:33:00, 14:38:...|\n", "|10.TA.30-170-Y-j1...|[8503202, 8502209...|[10:30:00, 10:35:...|[10:30:00, 10:35:...|\n", "|43.TA.26-2-j19-1....|[8503204, 8503202...|[09:24:00, 09:29:...|[09:23:00, 09:28:...|\n", "|580.TA.26-8-A-j19...|[8503204, 8503203...|[18:00:00, 18:02:...|[17:59:00, 18:02:...|\n", "|585.TA.26-24-j19-...|[8503305, 8503307...|[17:53:00, 17:57:...|[17:52:00, 17:57:...|\n", "|246.TA.26-9-A-j19...|[8503313, 8503312...|[10:02:00, 10:05:...|[10:02:00, 10:05:...|\n", "|158.TA.26-9-A-j19...|[8503313, 8503312...|[15:32:00, 15:35:...|[15:32:00, 15:35:...|\n", "|137.TA.26-15-j19-...|[8503316, 8503315...|[10:11:00, 10:14:...|[10:11:00, 10:14:...|\n", "|293.TA.26-640-j19...|[8503382, 8594339...|[08:26:00, 08:27:...|[08:26:00, 08:27:...|\n", "|278.TA.79-24-j19-...| [8503499, 8503500]|[12:25:00, 12:28:00]|[12:25:00, 12:28:00]|\n", "|127.TA.1-17-A-j19...|[8503508, 8517376...|[14:33:00, 14:34:...|[14:33:00, 14:34:...|\n", "|1859.TA.26-9-B-j1...|[8503610, 8580912...|[08:29:00, 08:30:...|[08:29:00, 08:30:...|\n", "|476.TA.26-768-j19...|[8573205, 8573213...|[14:37:00, 14:38:...|[14:37:00, 14:38:...|\n", "|40.TA.26-733-j19-...|[8573205, 8580301...|[14:33:00, 14:33:...|[14:33:00, 14:33:...|\n", "|120.TA.26-731-j19...|[8573205, 8580301...|[12:03:00, 12:03:...|[12:03:00, 12:03:...|\n", "+--------------------+--------------------+--------------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "trips_with_duplicates.dropDuplicates(['all_stops', 'all_departures', 'all_arrivals']).show()" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "20086" ] } ], "source": [ "trips_with_duplicates.dropDuplicates(['all_stops', 'all_departures', 'all_arrivals']).count()" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "20041" ] } ], "source": [ "trips_with_duplicates.dropDuplicates(['all_stops', 'all_departures']).count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There seem to be a fraction of trips (less 0.2%) that share the exact same departure times at all stops, but not the same arrival times at all stops. To be on the safe side, we define identical trips based on the sequence of stops and the sequence of departure times.\n", "\n", "All in all, we remove ~5000 duplicated trips from all trips." ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "trips_unique = trips_with_duplicates.dropDuplicates(['all_stops', 'all_departures'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lastly, we remove trips that only serve a single stop (most likely due to the pruning of stops ouside the 15km radius of Zürich HB)" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# removing trips with a single stop only:\n", "trips_unique = trips_unique.withColumn(\"stop_count\", slen(trips_with_duplicates.all_stops)).filter(F.col('stop_count')>1)" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+\n", "| trip_id| all_stops| all_departures| all_arrivals|stop_count|\n", "+--------------------+--------------------+--------------------+--------------------+----------+\n", "|168.TA.1-17-A-j19...|[8502273, 8517377...|[17:51:00, 17:52:...|[17:51:00, 17:52:...| 7|\n", "|15.TA.80-53-Y-j19...| [8503000, 8503202]|[09:12:00, 09:21:00]|[09:12:00, 09:21:00]| 2|\n", "|80.TA.16-5-j19-1....|[8503016, 8503006...|[19:09:00, 19:15:...|[19:07:00, 19:13:...| 3|\n", "|136.TA.26-10-B-j1...|[8503057, 8503056...|[12:54:00, 12:59:...|[12:54:00, 12:59:...| 8|\n", "|73.TA.26-4-B-j19-...|[8503088, 8503090...|[11:38:00, 11:39:...|[11:38:00, 11:39:...| 12|\n", "|55.TA.26-7-A-j19-...|[8503104, 8503003...|[14:03:00, 14:15:...|[14:02:00, 14:14:...| 11|\n", "|551.TA.26-11-j19-...|[8503147, 8503003...|[18:20:00, 18:25:...|[18:20:00, 18:25:...| 8|\n", "|216.TA.26-24-j19-...|[8503204, 8503203...|[19:15:00, 19:17:...|[19:15:00, 19:17:...| 12|\n", "|154.TA.26-9-A-j19...|[8503313, 8503312...|[13:32:00, 13:35:...|[13:32:00, 13:35:...| 13|\n", "|460.TA.79-24-j19-...| [8503499, 8503500]|[16:25:00, 16:28:00]|[16:25:00, 16:28:00]| 2|\n", "|159.TA.79-24-j19-...| [8503500, 8503499]|[12:40:00, 12:43:00]|[12:40:00, 12:43:00]| 2|\n", "|99.TA.79-24-j19-1...| [8503500, 8503499]|[17:40:00, 17:43:00]|[17:40:00, 17:43:00]| 2|\n", "|80.TA.26-36-j19-1...|[8503508, 8503001...|[11:38:00, 11:44:...|[11:36:00, 11:43:...| 5|\n", "|123.TA.1-350-j19-...|[8503610, 8573711...|[07:41:00, 07:43:...|[07:41:00, 07:43:...| 19|\n", "|4.TA.26-769-j19-1...|[8503700, 8576161...|[17:35:00, 17:37:...|[17:35:00, 17:37:...| 10|\n", "|281.TA.26-660-j19...|[8503700, 8588316...|[09:15:00, 09:16:...|[09:15:00, 09:16:...| 14|\n", "|269.TA.26-660-j19...|[8503700, 8588316...|[09:45:00, 09:46:...|[09:45:00, 09:46:...| 14|\n", "|983.TA.26-136-j19...|[8503855, 8594182...|[07:50:00, 07:51:...|[07:50:00, 07:51:...| 6|\n", "|7.TA.90-71-Y-j19-...|[8530645, 8530646...|[14:07:00, 14:15:...|[14:07:00, 14:11:...| 3|\n", "|138.TA.1-350-j19-...|[8572560, 8572599...|[17:49:00, 17:50:...|[17:49:00, 17:50:...| 20|\n", "+--------------------+--------------------+--------------------+--------------------+----------+\n", "only showing top 20 rows" ] } ], "source": [ "trips_unique.show()" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "19614" ] } ], "source": [ "trips_unique.count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 6) building routes\n", "\n", "- 6) building routes based on unique trips\n", " - order unique_trips by stop_sequence, earliest departure time\n", " - each window with the same stop_sequence gets a unique routeID\n", " \n", "- 7) generate a RAPTOR compatible stop_times\n", " - filter with unique_trips\n", " - sort by routeID, earliest departure time\n", " \n", "We start by getting the first departure time for each unique trip, to be able to order them by route and first departure time for RAPTOR's `stopTimes` data structure." ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\n", "| trip_id| all_stops| all_departures| all_arrivals|stop_count|departure_first_stop|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\n", "|168.TA.1-17-A-j19...|[8502273, 8517377...|[17:51:00, 17:52:...|[17:51:00, 17:52:...| 7| 17:51:00|\n", "|15.TA.80-53-Y-j19...| [8503000, 8503202]|[09:12:00, 09:21:00]|[09:12:00, 09:21:00]| 2| 09:12:00|\n", "|429.TA.16-5-j19-1...|[8503016, 8503006...|[19:09:00, 19:15:...|[19:07:00, 19:13:...| 3| 19:09:00|\n", "|136.TA.26-10-B-j1...|[8503057, 8503056...|[12:54:00, 12:59:...|[12:54:00, 12:59:...| 8| 12:54:00|\n", "|73.TA.26-4-B-j19-...|[8503088, 8503090...|[11:38:00, 11:39:...|[11:38:00, 11:39:...| 12| 11:38:00|\n", "|55.TA.26-7-A-j19-...|[8503104, 8503003...|[14:03:00, 14:15:...|[14:02:00, 14:14:...| 11| 14:03:00|\n", "|551.TA.26-11-j19-...|[8503147, 8503003...|[18:20:00, 18:25:...|[18:20:00, 18:25:...| 8| 18:20:00|\n", "|216.TA.26-24-j19-...|[8503204, 8503203...|[19:15:00, 19:17:...|[19:15:00, 19:17:...| 12| 19:15:00|\n", "|154.TA.26-9-A-j19...|[8503313, 8503312...|[13:32:00, 13:35:...|[13:32:00, 13:35:...| 13| 13:32:00|\n", "|460.TA.79-24-j19-...| [8503499, 8503500]|[16:25:00, 16:28:00]|[16:25:00, 16:28:00]| 2| 16:25:00|\n", "|159.TA.79-24-j19-...| [8503500, 8503499]|[12:40:00, 12:43:00]|[12:40:00, 12:43:00]| 2| 12:40:00|\n", "|99.TA.79-24-j19-1...| [8503500, 8503499]|[17:40:00, 17:43:00]|[17:40:00, 17:43:00]| 2| 17:40:00|\n", "|80.TA.26-36-j19-1...|[8503508, 8503001...|[11:38:00, 11:44:...|[11:36:00, 11:43:...| 5| 11:38:00|\n", "|123.TA.1-350-j19-...|[8503610, 8573711...|[07:41:00, 07:43:...|[07:41:00, 07:43:...| 19| 07:41:00|\n", "|4.TA.26-769-j19-1...|[8503700, 8576161...|[17:35:00, 17:37:...|[17:35:00, 17:37:...| 10| 17:35:00|\n", "|280.TA.26-660-j19...|[8503700, 8588316...|[09:15:00, 09:16:...|[09:15:00, 09:16:...| 14| 09:15:00|\n", "|269.TA.26-660-j19...|[8503700, 8588316...|[09:45:00, 09:46:...|[09:45:00, 09:46:...| 14| 09:45:00|\n", "|983.TA.26-136-j19...|[8503855, 8594182...|[07:50:00, 07:51:...|[07:50:00, 07:51:...| 6| 07:50:00|\n", "|7.TA.90-71-Y-j19-...|[8530645, 8530646...|[14:07:00, 14:15:...|[14:07:00, 14:11:...| 3| 14:07:00|\n", "|138.TA.1-350-j19-...|[8572560, 8572599...|[17:49:00, 17:50:...|[17:49:00, 17:50:...| 20| 17:49:00|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "# code from https://stackoverflow.com/questions/52975567/get-first-n-elements-from-dataframe-arraytype-column-in-pyspark\n", "\n", "trips_unique = trips_unique.withColumn('departure_first_stop', F.col(\"all_departures\")[0])\n", "trips_unique.show()" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\n", "| trip_id| all_stops| all_departures| all_arrivals|stop_count|departure_first_stop|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\n", "|203.TA.1-17-A-j19...|[8502187, 8502277...|[07:01:00, 07:02:...|[07:01:00, 07:02:...| 7| 07:01:00|\n", "|4.TA.30-57-Y-j19-...|[8502208, 8502209...|[07:18:00, 07:23:...|[07:18:00, 07:23:...| 3| 07:18:00|\n", "|5.TA.30-57-Y-j19-...|[8502208, 8502209...|[07:48:00, 07:53:...|[07:48:00, 07:53:...| 3| 07:48:00|\n", "|6.TA.30-57-Y-j19-...|[8502208, 8502209...|[08:18:00, 08:23:...|[08:18:00, 08:23:...| 3| 08:18:00|\n", "|7.TA.30-57-Y-j19-...|[8502208, 8502209...|[08:48:00, 08:53:...|[08:48:00, 08:53:...| 3| 08:48:00|\n", "|8.TA.30-57-Y-j19-...|[8502208, 8502209...|[09:18:00, 09:23:...|[09:18:00, 09:23:...| 3| 09:18:00|\n", "|9.TA.30-57-Y-j19-...|[8502208, 8502209...|[09:48:00, 09:53:...|[09:48:00, 09:53:...| 3| 09:48:00|\n", "|10.TA.30-57-Y-j19...|[8502208, 8502209...|[10:18:00, 10:23:...|[10:18:00, 10:23:...| 3| 10:18:00|\n", "|11.TA.30-57-Y-j19...|[8502208, 8502209...|[10:48:00, 10:53:...|[10:48:00, 10:53:...| 3| 10:48:00|\n", "|12.TA.30-57-Y-j19...|[8502208, 8502209...|[11:18:00, 11:23:...|[11:18:00, 11:23:...| 3| 11:18:00|\n", "|13.TA.30-57-Y-j19...|[8502208, 8502209...|[11:48:00, 11:53:...|[11:48:00, 11:53:...| 3| 11:48:00|\n", "|14.TA.30-57-Y-j19...|[8502208, 8502209...|[12:18:00, 12:23:...|[12:18:00, 12:23:...| 3| 12:18:00|\n", "|15.TA.30-57-Y-j19...|[8502208, 8502209...|[12:48:00, 12:53:...|[12:48:00, 12:53:...| 3| 12:48:00|\n", "|16.TA.30-57-Y-j19...|[8502208, 8502209...|[13:18:00, 13:23:...|[13:18:00, 13:23:...| 3| 13:18:00|\n", "|17.TA.30-57-Y-j19...|[8502208, 8502209...|[13:48:00, 13:53:...|[13:48:00, 13:53:...| 3| 13:48:00|\n", "|18.TA.30-57-Y-j19...|[8502208, 8502209...|[14:18:00, 14:23:...|[14:18:00, 14:23:...| 3| 14:18:00|\n", "|19.TA.30-57-Y-j19...|[8502208, 8502209...|[14:48:00, 14:53:...|[14:48:00, 14:53:...| 3| 14:48:00|\n", "|20.TA.30-57-Y-j19...|[8502208, 8502209...|[15:18:00, 15:23:...|[15:18:00, 15:23:...| 3| 15:18:00|\n", "|21.TA.30-57-Y-j19...|[8502208, 8502209...|[15:48:00, 15:53:...|[15:48:00, 15:53:...| 3| 15:48:00|\n", "|22.TA.30-57-Y-j19...|[8502208, 8502209...|[16:18:00, 16:23:...|[16:18:00, 16:23:...| 3| 16:18:00|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "#ordering by stop_sequence (arbitrary order) and departure at the first stop (ascending)\n", "trips_unique = trips_unique.sort(trips_unique.all_stops, trips_unique.departure_first_stop)\n", "trips_unique.show()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In RAPTOR, routes are defined as collections of unique trips serving the same stop sequences at different times. Therefore, there is one route per sequence of stops, i.e unique entry in column `all_stops`. However, there is no specific rule to order routes depending on the stops they serve. We simply subset unique sequences of stops and index them from 0 to n-1 routes." ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+\n", "| all_stops|\n", "+--------------------+\n", "|[8576240, 8591353...|\n", "|[8591061, 8591270...|\n", "| [8591281, 8591046]|\n", "|[8591825, 8590504...|\n", "| [8573205, 8588553]|\n", "|[8591049, 8591128...|\n", "|[8591057, 8591402...|\n", "|[8575921, 8575920...|\n", "|[8591035, 8591134...|\n", "|[8595129, 8590543...|\n", "|[8591031, 8588553...|\n", "|[8503010, 8503011...|\n", "| [8575927, 8594339]|\n", "|[8576127, 8576139...|\n", "|[8502208, 8502209...|\n", "|[8503674, 8503659...|\n", "|[8576171, 8576172...|\n", "|[8591110, 8591306...|\n", "|[8576276, 8576277...|\n", "|[8590805, 8590794...|\n", "+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "routes = trips_unique.select(trips_unique.all_stops).distinct()\n", "routes.show()" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#building an index from 0 to n_routes\n", "# code from https://stackoverflow.com/questions/39057766/spark-equivelant-of-zipwithindex-in-dataframe\n", "from pyspark.sql.types import StructType, StructField, LongType\n", "def dfZipWithIndex (df, offset=0, colName=\"rowId\"):\n", " '''\n", " Enumerates dataframe rows is native order, like rdd.ZipWithIndex(), but on a dataframe \n", " and preserves a schema\n", "\n", " :param df: source dataframe\n", " :param offset: adjustment to zipWithIndex()'s index\n", " :param colName: name of the index column\n", " '''\n", "\n", " new_schema = StructType(\n", " [StructField(colName,LongType(),True)] # new added field in front\n", " + df.schema.fields # previous schema\n", " )\n", "\n", " zipped_rdd = df.rdd.zipWithIndex()\n", "\n", " new_rdd = zipped_rdd.map(lambda args: ([args[1] + offset] + list(args[0])))\n", "\n", " return spark.createDataFrame(new_rdd, new_schema)" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+---------+--------------------+\n", "|route_int| all_stops|\n", "+---------+--------------------+\n", "| 0|[8576240, 8591353...|\n", "| 1|[8591061, 8591270...|\n", "| 2|[8591825, 8590504...|\n", "| 3| [8573205, 8588553]|\n", "| 4|[8591049, 8591128...|\n", "| 5|[8591057, 8591402...|\n", "| 6| [8591281, 8591046]|\n", "| 7|[8575921, 8575920...|\n", "| 8|[8591035, 8591134...|\n", "| 9|[8595129, 8590543...|\n", "| 10|[8576127, 8576139...|\n", "| 11|[8503010, 8503011...|\n", "| 12| [8575927, 8594339]|\n", "| 13|[8591031, 8588553...|\n", "| 14|[8502208, 8502209...|\n", "| 15|[8503674, 8503659...|\n", "| 16|[8590805, 8590794...|\n", "| 17|[8576171, 8576172...|\n", "| 18|[8576276, 8576277...|\n", "| 19|[8591110, 8591306...|\n", "+---------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "routes_indexed = dfZipWithIndex(routes, 0, 'route_int')\n", "routes_indexed.show()" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "| all_stops| trip_id| all_departures| all_arrivals|stop_count|departure_first_stop|route_int|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "|[8572747, 8580847...|59.TA.1-322-j19-1...|[16:27:00, 16:27:...|[16:27:00, 16:27:...| 3| 16:27:00| 30|\n", "|[8503064, 8503065...|483.TA.26-18-j19-...|[10:41:00, 10:45:...|[10:41:00, 10:45:...| 14| 10:41:00| 41|\n", "|[8591355, 8591354...|1144.TA.26-75-A-j...|[11:52:00, 11:53:...|[11:52:00, 11:53:...| 21| 11:52:00| 76|\n", "|[8591355, 8591354...|1187.TA.26-75-A-j...|[08:36:00, 08:37:...|[08:36:00, 08:37:...| 21| 08:36:00| 76|\n", "|[8591276, 8591101...|613.TA.26-69-j19-...|[18:20:00, 18:23:...|[18:20:00, 18:23:...| 9| 18:20:00| 105|\n", "|[8591123, 8591174...|59.TA.26-E-j19-1.4.R|[15:14:00, 15:17:...|[15:14:00, 15:17:...| 3| 15:14:00| 119|\n", "|[8502495, 8591081...|58.TA.26-185-j19-...|[19:19:00, 19:21:...|[19:19:00, 19:21:...| 16| 19:19:00| 177|\n", "| [8503081, 8503082]|1373.TA.26-LAF-j1...|[17:20:00, 17:25:00]|[17:20:00, 17:25:00]| 2| 17:20:00| 212|\n", "|[8590878, 8576280...|15.TA.26-453-j19-...|[18:53:00, 18:53:...|[18:53:00, 18:53:...| 6| 18:53:00| 268|\n", "|[8503202, 8502209...|14.TA.30-170-Y-j1...|[12:30:00, 12:35:...|[12:30:00, 12:35:...| 3| 12:30:00| 285|\n", "|[8587653, 8590575...|75.TA.26-748-j19-...|[19:00:00, 19:00:...|[19:00:00, 19:00:...| 13| 19:00:00| 398|\n", "|[8591122, 8591201...|1133.TA.26-69-j19...|[17:37:00, 17:38:...|[17:37:00, 17:38:...| 9| 17:37:00| 400|\n", "| [8503001, 8503000]|282.TA.6-17-j19-1...|[15:00:00, 15:06:00]|[15:00:00, 15:06:00]| 2| 15:00:00| 452|\n", "|[8502224, 8502223...|105.TA.26-5-A-j19...|[18:22:00, 18:25:...|[18:22:00, 18:25:...| 11| 18:22:00| 480|\n", "|[8503610, 8580912...|990.TA.26-14-A-j1...|[07:10:00, 07:11:...|[07:10:00, 07:11:...| 27| 07:10:00| 513|\n", "| [8575918, 8576176]|6.TA.26-662-j19-1...|[07:37:00, 07:47:00]|[07:37:00, 07:47:00]| 2| 07:37:00| 530|\n", "|[8575944, 8503374...|138.TA.26-650-j19...|[15:44:00, 15:46:...|[15:44:00, 15:46:...| 14| 15:44:00| 615|\n", "|[8576182, 8576200...|522.TA.26-4-j19-1...|[16:01:00, 16:02:...|[16:01:00, 16:02:...| 26| 16:01:00| 630|\n", "|[8576182, 8576200...|626.TA.26-4-j19-1...|[08:55:00, 08:56:...|[08:55:00, 08:56:...| 26| 08:55:00| 630|\n", "|[8576182, 8576200...|639.TA.26-4-j19-1...|[08:17:00, 08:18:...|[08:17:00, 08:18:...| 26| 08:17:00| 630|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "only showing top 20 rows" ] } ], "source": [ "trips_unique = trips_unique.join(routes_indexed, how='inner', on='all_stops').dropDuplicates()\n", "trips_unique.show()" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "| all_stops| trip_id| all_departures| all_arrivals|stop_count|departure_first_stop|route_int|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "|8572747 8580847 8...|59.TA.1-322-j19-1...|16:27:00 16:27:00...|16:27:00 16:27:00...| 3| 16:27:00| 30|\n", "|8503064 8503065 8...|483.TA.26-18-j19-...|10:41:00 10:45:00...|10:41:00 10:45:00...| 14| 10:41:00| 41|\n", "|8573504 8580879 8...|122.TA.26-845-j19...|11:45:00 11:47:00...|11:45:00 11:47:00...| 4| 11:45:00| 52|\n", "|8591355 8591354 8...|1144.TA.26-75-A-j...|11:52:00 11:53:00...|11:52:00 11:53:00...| 21| 11:52:00| 76|\n", "|8591355 8591354 8...|1187.TA.26-75-A-j...|08:36:00 08:37:00...|08:36:00 08:37:00...| 21| 08:36:00| 76|\n", "|8591276 8591101 8...|613.TA.26-69-j19-...|18:20:00 18:23:00...|18:20:00 18:23:00...| 9| 18:20:00| 105|\n", "|8503150 8576140 8...|107.TA.26-726-j19...|19:02:00 19:02:00...|19:02:00 19:02:00...| 11| 19:02:00| 122|\n", "|8502495 8591081 8...|132.TA.26-185-j19...|14:19:00 14:21:00...|14:19:00 14:21:00...| 16| 14:19:00| 177|\n", "| 8503081 8503082|1373.TA.26-LAF-j1...| 17:20:00 17:25:00| 17:20:00 17:25:00| 2| 17:20:00| 212|\n", "|8591067 8587349 8...|1647.TA.26-17-j19...|16:03:00 16:06:00...|16:03:00 16:06:00...| 17| 16:03:00| 221|\n", "|8591349 8591188 8...|30.TA.26-79-j19-1...|17:38:00 17:39:00...|17:38:00 17:39:00...| 6| 17:38:00| 222|\n", "|8580433 8580438 8...|194.TA.26-733-j19...|15:15:00 15:16:00...|15:15:00 15:16:00...| 10| 15:15:00| 240|\n", "|8590878 8576280 8...|15.TA.26-453-j19-...|18:53:00 18:53:00...|18:53:00 18:53:00...| 6| 18:53:00| 268|\n", "|8590716 8590714 8...|364.TA.26-743-j19...|15:30:00 15:30:00...|15:30:00 15:30:00...| 17| 15:30:00| 278|\n", "|8590804 8590805 8...|689.TA.26-31-j19-...|17:36:00 17:37:00...|17:36:00 17:37:00...| 9| 17:36:00| 279|\n", "| 8596126 8573205|4.TA.6-E02-j19-1.4.R| 14:50:00 15:10:00| 14:45:00 15:10:00| 2| 14:50:00| 283|\n", "|8587653 8590575 8...|75.TA.26-748-j19-...|19:00:00 19:00:00...|19:00:00 19:00:00...| 13| 19:00:00| 398|\n", "|8591122 8591201 8...|1133.TA.26-69-j19...|17:37:00 17:38:00...|17:37:00 17:38:00...| 9| 17:37:00| 400|\n", "|8503059 8530813 8...|427.TA.26-18-j19-...|14:33:00 14:34:00...|14:33:00 14:34:00...| 13| 14:33:00| 432|\n", "|8502224 8502223 8...|105.TA.26-5-A-j19...|18:22:00 18:25:00...|18:22:00 18:25:00...| 11| 18:22:00| 480|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "only showing top 20 rows" ] } ], "source": [ "# converting arrays to strings to be able to store the data as csv\n", "trips_unique_string_lists = trips_unique.withColumn(\"all_stops\", F.concat_ws(\" \", \"all_stops\"))\\\n", ".withColumn(\"all_departures\", F.concat_ws(\" \", \"all_departures\"))\\\n", ".withColumn(\"all_arrivals\", F.concat_ws(\" \", \"all_arrivals\"))\n", "trips_unique_string_lists.show()" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "trips_unique_string_lists.write.csv('data/lgpt_guys/trips_unique_string_lists.csv', header = True, mode=\"overwrite\")" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "| all_stops| trip_id| all_departures| all_arrivals|stop_count|departure_first_stop|route_int|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "|8591057 8591402 8...|159.TA.26-304-j19...|19:39:00 19:41:00...|19:39:00 19:41:00...| 17| 19:39:00| 2|\n", "|8591355 8591354 8...|1171.TA.26-75-A-j...|09:37:00 09:38:00...|09:37:00 09:38:00...| 21| 09:37:00| 77|\n", "|8591401 8503610 8...|1282.TA.26-80-j19...|18:44:00 18:46:00...|18:44:00 18:46:00...| 29| 18:44:00| 110|\n", "|8591401 8503610 8...|1258.TA.26-80-j19...|09:29:00 09:31:00...|09:29:00 09:31:00...| 29| 09:29:00| 110|\n", "|8503157 8587858 8...|176.TA.26-725-j19...|15:17:00 15:19:00...|15:17:00 15:19:00...| 10| 15:17:00| 292|\n", "|8587653 8590575 8...|73.TA.26-752-j19-...|08:25:00 08:26:00...|08:25:00 08:26:00...| 8| 08:25:00| 310|\n", "|8591439 8591106 8...|1353.TA.26-7-B-j1...|16:42:00 16:44:00...|16:42:00 16:44:00...| 31| 16:42:00| 321|\n", "|8591439 8591106 8...|1366.TA.26-7-B-j1...|16:35:00 16:36:00...|16:35:00 16:36:00...| 31| 16:35:00| 321|\n", "|8590600 8579968 8...|49.TA.26-732-j19-...|11:39:00 11:40:00...|11:39:00 11:40:00...| 14| 11:39:00| 349|\n", "|8590275 8590279 8...|412.TA.1-4-B-j19-...|18:05:00 18:07:00...|18:05:00 18:07:00...| 6| 18:05:00| 369|\n", "|8590464 8590474 8...|642.TA.26-184-j19...|12:11:00 12:12:00...|12:11:00 12:12:00...| 9| 12:11:00| 384|\n", "|8591122 8591201 8...|1180.TA.26-69-j19...|11:45:00 11:46:00...|11:45:00 11:46:00...| 9| 11:45:00| 401|\n", "|8591122 8591201 8...|1201.TA.26-69-j19...|09:08:00 09:09:00...|09:08:00 09:09:00...| 9| 09:08:00| 401|\n", "|8591122 8591201 8...|1208.TA.26-69-j19...|08:15:00 08:16:00...|08:15:00 08:16:00...| 9| 08:15:00| 401|\n", "|8591230 8591087 8...|238.TA.26-751-j19...|11:16:00 11:17:00...|11:16:00 11:17:00...| 9| 11:16:00| 406|\n", "|8591349 8591403 8...|636.TA.26-62-j19-...|14:47:00 14:47:00...|14:47:00 14:47:00...| 20| 14:47:00| 430|\n", "|8503855 8589111 8...|863.TA.26-131-j19...|10:14:00 10:15:00...|10:14:00 10:15:00...| 7| 10:14:00| 528|\n", "|8594304 8594310 8...|26.TA.1-11-B-j19-...|18:46:00 18:47:00...|18:46:00 18:47:00...| 5| 18:46:00| 544|\n", "|8575918 8576135 8...|119.TA.26-720-j19...|07:23:00 07:25:00...|07:23:00 07:25:00...| 13| 07:23:00| 581|\n", "|8576182 8576200 8...|648.TA.26-4-j19-1...|08:02:00 08:03:00...|08:02:00 08:03:00...| 26| 08:02:00| 629|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "only showing top 20 rows" ] } ], "source": [ "# we prepare an inner join on trips from trips_unique with stopTimes.\n", "\n", "trips_unique_string_lists = spark.read.csv('data/lgpt_guys/trips_unique_string_lists.csv', header = True)\n", "trips_unique_string_lists.show()" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+---------+----------+\n", "| trip_id|departure_first_stop|route_int|stop_count|\n", "+--------------------+--------------------+---------+----------+\n", "|159.TA.26-304-j19...| 19:39:00| 2| 17|\n", "|1171.TA.26-75-A-j...| 09:37:00| 77| 21|\n", "|1282.TA.26-80-j19...| 18:44:00| 110| 29|\n", "|1258.TA.26-80-j19...| 09:29:00| 110| 29|\n", "|176.TA.26-725-j19...| 15:17:00| 292| 10|\n", "|73.TA.26-752-j19-...| 08:25:00| 310| 8|\n", "|1353.TA.26-7-B-j1...| 16:42:00| 321| 31|\n", "|1366.TA.26-7-B-j1...| 16:35:00| 321| 31|\n", "|49.TA.26-732-j19-...| 11:39:00| 349| 14|\n", "|412.TA.1-4-B-j19-...| 18:05:00| 369| 6|\n", "|642.TA.26-184-j19...| 12:11:00| 384| 9|\n", "|1180.TA.26-69-j19...| 11:45:00| 401| 9|\n", "|1201.TA.26-69-j19...| 09:08:00| 401| 9|\n", "|1208.TA.26-69-j19...| 08:15:00| 401| 9|\n", "|238.TA.26-751-j19...| 11:16:00| 406| 9|\n", "|636.TA.26-62-j19-...| 14:47:00| 430| 20|\n", "|863.TA.26-131-j19...| 10:14:00| 528| 7|\n", "|26.TA.1-11-B-j19-...| 18:46:00| 544| 5|\n", "|119.TA.26-720-j19...| 07:23:00| 581| 13|\n", "|648.TA.26-4-j19-1...| 08:02:00| 629| 26|\n", "+--------------------+--------------------+---------+----------+\n", "only showing top 20 rows" ] } ], "source": [ "trips_unique_for_join = trips_unique_string_lists.select(trips_unique_string_lists.trip_id, \\\n", " trips_unique_string_lists.departure_first_stop, \\\n", " trips_unique_string_lists.route_int, \\\n", " trips_unique_string_lists.stop_count)\n", "trips_unique_for_join.show()" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "260459" ] } ], "source": [ "stop_times = stop_times.join(trips_unique_for_join, how='inner', on='trip_id')\n", "stop_times.count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At this step, we sort `stop_times` in the same order as RAPTOR's `stopTimes` data structure, that is:\n", "- By route\n", "- By trip (starting with the one that leaves the first stop of the route at the earliest departure time)\n", "- By stop in the sequence of stops defining the route\n" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+--------------------+---------+----------+\n", "| trip_id|stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|departure_first_stop|route_int|stop_count|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+--------------------+---------+----------+\n", "|1672.TA.26-10-j19...|8573205| 07:00:00| 07:01:00| 27| 0| 0| 8573205|Zürich Flughafen,...| 26-10-j19-1|Zürich Flughafen,...| 4096| 1| 7| 07:01:00| 0| 2|\n", "|1672.TA.26-10-j19...|8588553| 07:02:00| 07:02:00| 28| 0| 0| 8588553|Zürich Flughafen,...| 26-10-j19-1|Zürich Flughafen,...| 4096| 1| 7| 07:01:00| 0| 2|\n", "|791.TA.26-11-A-j1...|8591049| 19:49:00| 19:49:00| 1| 0| 0| 8591049| Zürich, Auzelg|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8591128| 19:51:00| 19:51:00| 2| 0| 0| 8591128|Zürich, Fernsehst...|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8591830| 19:52:00| 19:52:00| 3| 0| 0| 8591830|Glattpark, Glattpark|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8591294| 19:53:00| 19:53:00| 4| 0| 0| 8591294| Zürich, Oerlikerhus|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8591256| 19:54:00| 19:54:00| 5| 0| 0| 8591256|Zürich, Leutschen...|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8591273| 19:55:00| 19:55:00| 6| 0| 0| 8591273|Zürich, Messe/Hal...|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8591382| 19:57:00| 19:57:00| 7| 0| 0| 8591382|Zürich, Sternen O...|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|791.TA.26-11-A-j1...|8580449| 19:59:00| 19:59:00| 8| 0| 0| 8580449|Zürich Oerlikon, ...|26-11-A-j19-1| Zürich, Rehalp| 363| 0| 19| 19:49:00| 1| 8|\n", "|159.TA.26-304-j19...|8591057| 19:39:00| 19:39:00| 1| 0| 0| 8591057|Zürich Altstetten...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8591402| 19:41:00| 19:41:00| 2| 0| 0| 8591402| Zürich, Tüffenwies| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8591434| 19:41:00| 19:41:00| 3| 0| 0| 8591434| Zürich, Winzerhalde| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8591197| 19:42:00| 19:42:00| 4| 0| 0| 8591197|Zürich, Hohenklin...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8591436| 19:43:00| 19:43:00| 5| 0| 0| 8591436|Zürich, Winzerstr...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8591136| 19:46:00| 19:46:00| 6| 0| 0| 8591136| Zürich, Frankental| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590725| 19:47:00| 19:47:00| 7| 0| 0| 8590725|Oberengstringen, ...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590726| 19:48:00| 19:48:00| 8| 0| 0| 8590726|Oberengstringen, ...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590728| 19:49:00| 19:49:00| 9| 0| 0| 8590728|Oberengstringen, ...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590727| 19:50:00| 19:50:00| 10| 0| 0| 8590727|Oberengstringen, ...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590833| 19:51:00| 19:51:00| 11| 0| 0| 8590833|Unterengstringen,...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8594732| 19:53:00| 19:53:00| 12| 0| 0| 8594732|Unterengstringen,...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590831| 19:53:00| 19:53:00| 13| 0| 0| 8590831|Unterengstringen,...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590911| 19:55:00| 19:55:00| 14| 0| 0| 8590911|Weiningen ZH, Aus...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590913| 19:56:00| 19:56:00| 15| 0| 0| 8590913|Weiningen ZH, Lin...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590914| 19:57:00| 19:57:00| 16| 0| 0| 8590914|Weiningen ZH, Sch...| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|159.TA.26-304-j19...|8590617| 19:59:00| 19:59:00| 17| 0| 0| 8590617| Geroldswil, Welbrig| 26-304-j19-1| Dietikon, Bahnhof| 5481| 1| 19| 19:39:00| 2| 17|\n", "|269.TA.26-61-j19-...|8591281| 19:57:00| 19:57:00| 1| 0| 0| 8591281| Zürich, Mühlacker| 26-61-j19-1|Zürich, Schwamend...| 2076| 0| 19| 19:57:00| 3| 2|\n", "|269.TA.26-61-j19-...|8591046| 19:58:00| 19:58:00| 2| 0| 0| 8591046| Zürich, Aspholz| 26-61-j19-1|Zürich, Schwamend...| 2076| 0| 19| 19:57:00| 3| 2|\n", "|2064.TA.26-13-j19...|8576240| 07:00:00| 07:00:00| 5| 0| 0| 8576240|Zürich, Meierhofp...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591353| 07:01:00| 07:01:00| 6| 0| 0| 8591353| Zürich, Schwert| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591039| 07:02:00| 07:02:00| 7| 0| 0| 8591039| Zürich, Alte Trotte| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591121| 07:03:00| 07:03:00| 8| 0| 0| 8591121|Zürich, Eschergutweg| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591417| 07:05:00| 07:05:00| 9| 0| 0| 8591417| Zürich, Waidfussweg| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591437| 07:06:00| 07:06:00| 10| 0| 0| 8591437|Zürich, Wipkinger...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8580522| 07:08:00| 07:08:00| 11| 0| 0| 8580522|Zürich, Escher-Wy...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591110| 07:09:00| 07:09:00| 12| 0| 0| 8591110| Zürich, Dammweg| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591306| 07:10:00| 07:10:00| 13| 0| 0| 8591306|Zürich, Quellenst...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591257| 07:11:00| 07:11:00| 14| 0| 0| 8591257| Zürich, Limmatplatz| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591282| 07:12:00| 07:12:00| 15| 0| 0| 8591282|Zürich, Museum fü...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591368| 07:14:00| 07:14:00| 16| 0| 0| 8591368| Zürich, Sihlquai/HB| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8587349| 07:16:00| 07:16:00| 17| 0| 0| 8587349|Zürich, Bahnhofqu...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591067| 07:18:00| 07:18:00| 18| 0| 0| 8591067|Zürich, Bahnhofst...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591316| 07:20:00| 07:20:00| 19| 0| 0| 8591316| Zürich, Rennweg| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591299| 07:22:00| 07:22:00| 20| 0| 0| 8591299| Zürich, Paradeplatz| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591384| 07:23:00| 07:23:00| 21| 0| 0| 8591384|Zürich, Stockerst...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591404| 07:24:00| 07:24:00| 22| 0| 0| 8591404|Zürich, Tunnelstr...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591059| 07:25:00| 07:25:00| 23| 0| 0| 8591059|Zürich Enge, Bahn...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591415| 07:27:00| 07:27:00| 24| 0| 0| 8591415|Zürich, Waffenpla...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591366| 07:28:00| 07:28:00| 25| 0| 0| 8591366|Zürich, Sihlcity ...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591329| 07:29:00| 07:29:00| 26| 0| 0| 8591329|Zürich, Saalsport...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591245| 07:30:00| 07:30:00| 27| 0| 0| 8591245| Zürich, Laubegg| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591405| 07:32:00| 07:32:00| 28| 0| 0| 8591405| Zürich, Uetlihof| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591385| 07:33:00| 07:33:00| 29| 0| 0| 8591385|Zürich, Strassenv...| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|2064.TA.26-13-j19...|8591034| 07:34:00| 07:34:00| 30| 0| 0| 8591034| Zürich, Albisgütli| 26-13-j19-1| Zürich, Albisgütli| 1831| 0| 7| 07:00:00| 4| 26|\n", "|966.TA.26-70-A-j1...|8591061| 07:00:00| 07:00:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|26-70-A-j19-1|Zürich, Mittellei...| 3928| 0| 7| 07:00:00| 5| 5|\n", "|966.TA.26-70-A-j1...|8591270| 07:02:00| 07:02:00| 10| 0| 0| 8591270| Zürich, Marbachweg|26-70-A-j19-1|Zürich, Mittellei...| 3928| 0| 7| 07:00:00| 5| 5|\n", "|966.TA.26-70-A-j1...|8591210| 07:03:00| 07:03:00| 11| 0| 0| 8591210| Zürich, Im Hüsli|26-70-A-j19-1|Zürich, Mittellei...| 3928| 0| 7| 07:00:00| 5| 5|\n", "|966.TA.26-70-A-j1...|8591370| 07:03:00| 07:03:00| 12| 0| 0| 8591370|Zürich, Sihlweids...|26-70-A-j19-1|Zürich, Mittellei...| 3928| 0| 7| 07:00:00| 5| 5|\n", "|966.TA.26-70-A-j1...|8591278| 07:04:00| 07:04:00| 13| 0| 0| 8591278|Zürich, Mittellei...|26-70-A-j19-1|Zürich, Mittellei...| 3928| 0| 7| 07:00:00| 5| 5|\n", "|179.TA.26-703-j19...|8591825| 07:10:00| 07:10:00| 1| 0| 0| 8591825| Benglen, Bodenacher| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8590504| 07:11:00| 07:11:00| 2| 0| 0| 8590504|Benglen, Gerlisbr...| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8596005| 07:14:00| 07:14:00| 3| 0| 0| 8596005|Binz bei Maur, Tw...| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8591832| 07:14:00| 07:14:00| 4| 0| 0| 8591832|Pfaffhausen, Müseren| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8591147| 07:16:00| 07:16:00| 5| 0| 0| 8591147|Zürich, Friedhof ...| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8591162| 07:17:00| 07:17:00| 6| 0| 0| 8591162|Zürich, Glockenacker| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8591261| 07:18:00| 07:18:00| 7| 0| 0| 8591261|Zürich, Loorenstr...| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8591107| 07:19:00| 07:19:00| 8| 0| 0| 8591107|Zürich, Carl-Spit...| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|179.TA.26-703-j19...|8591233| 07:25:00| 07:25:00| 9| 0| 0| 8591233| Zürich, Klusplatz| 26-703-j19-1| Zürich, Klusplatz| 9385| 1| 7| 07:10:00| 6| 9|\n", "|171.TA.26-703-j19...|8591825| 07:12:00| 07:12:00| 1| 0| 0| 8591825| Benglen, Bodenacher| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8590504| 07:13:00| 07:13:00| 2| 0| 0| 8590504|Benglen, Gerlisbr...| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8596005| 07:16:00| 07:16:00| 3| 0| 0| 8596005|Binz bei Maur, Tw...| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8591832| 07:16:00| 07:16:00| 4| 0| 0| 8591832|Pfaffhausen, Müseren| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8591147| 07:18:00| 07:18:00| 5| 0| 0| 8591147|Zürich, Friedhof ...| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8591162| 07:19:00| 07:19:00| 6| 0| 0| 8591162|Zürich, Glockenacker| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8591261| 07:20:00| 07:20:00| 7| 0| 0| 8591261|Zürich, Loorenstr...| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8591107| 07:21:00| 07:21:00| 8| 0| 0| 8591107|Zürich, Carl-Spit...| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|171.TA.26-703-j19...|8591233| 07:27:00| 07:27:00| 9| 0| 0| 8591233| Zürich, Klusplatz| 26-703-j19-1| Zürich, Klusplatz| 9346| 1| 7| 07:12:00| 6| 9|\n", "|155.TA.26-703-j19...|8591825| 07:25:00| 07:25:00| 1| 0| 0| 8591825| Benglen, Bodenacher| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8590504| 07:26:00| 07:26:00| 2| 0| 0| 8590504|Benglen, Gerlisbr...| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8596005| 07:29:00| 07:29:00| 3| 0| 0| 8596005|Binz bei Maur, Tw...| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8591832| 07:29:00| 07:29:00| 4| 0| 0| 8591832|Pfaffhausen, Müseren| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8591147| 07:31:00| 07:31:00| 5| 0| 0| 8591147|Zürich, Friedhof ...| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8591162| 07:32:00| 07:32:00| 6| 0| 0| 8591162|Zürich, Glockenacker| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8591261| 07:33:00| 07:33:00| 7| 0| 0| 8591261|Zürich, Loorenstr...| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8591107| 07:34:00| 07:34:00| 8| 0| 0| 8591107|Zürich, Carl-Spit...| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|155.TA.26-703-j19...|8591233| 07:40:00| 07:40:00| 9| 0| 0| 8591233| Zürich, Klusplatz| 26-703-j19-1| Zürich, Klusplatz| 9267| 1| 7| 07:25:00| 6| 9|\n", "|144.TA.26-703-j19...|8591825| 07:27:00| 07:27:00| 1| 0| 0| 8591825| Benglen, Bodenacher| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8590504| 07:28:00| 07:28:00| 2| 0| 0| 8590504|Benglen, Gerlisbr...| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8596005| 07:31:00| 07:31:00| 3| 0| 0| 8596005|Binz bei Maur, Tw...| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8591832| 07:31:00| 07:31:00| 4| 0| 0| 8591832|Pfaffhausen, Müseren| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8591147| 07:33:00| 07:33:00| 5| 0| 0| 8591147|Zürich, Friedhof ...| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8591162| 07:34:00| 07:34:00| 6| 0| 0| 8591162|Zürich, Glockenacker| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8591261| 07:35:00| 07:35:00| 7| 0| 0| 8591261|Zürich, Loorenstr...| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8591107| 07:36:00| 07:36:00| 8| 0| 0| 8591107|Zürich, Carl-Spit...| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|144.TA.26-703-j19...|8591233| 07:42:00| 07:42:00| 9| 0| 0| 8591233| Zürich, Klusplatz| 26-703-j19-1| Zürich, Klusplatz| 9231| 1| 7| 07:27:00| 6| 9|\n", "|120.TA.26-703-j19...|8591825| 07:40:00| 07:40:00| 1| 0| 0| 8591825| Benglen, Bodenacher| 26-703-j19-1| Zürich, Klusplatz| 9159| 1| 7| 07:40:00| 6| 9|\n", "|120.TA.26-703-j19...|8590504| 07:41:00| 07:41:00| 2| 0| 0| 8590504|Benglen, Gerlisbr...| 26-703-j19-1| Zürich, Klusplatz| 9159| 1| 7| 07:40:00| 6| 9|\n", "|120.TA.26-703-j19...|8596005| 07:44:00| 07:44:00| 3| 0| 0| 8596005|Binz bei Maur, Tw...| 26-703-j19-1| Zürich, Klusplatz| 9159| 1| 7| 07:40:00| 6| 9|\n", "|120.TA.26-703-j19...|8591832| 07:44:00| 07:44:00| 4| 0| 0| 8591832|Pfaffhausen, Müseren| 26-703-j19-1| Zürich, Klusplatz| 9159| 1| 7| 07:40:00| 6| 9|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+-------------+--------------------+---------------+------------+--------------+--------------------+---------+----------+\n", "only showing top 100 rows" ] } ], "source": [ "stop_times=stop_times.sort(stop_times.route_int.cast('int'), \n", " stop_times.departure_first_stop, \n", " stop_times.trip_id, \n", " stop_times.stop_sequence.cast('int'))\n", "stop_times.show(100)" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stop_times.write.csv('data/lgpt_guys/stop_times_with_route_int.csv', header=True, mode='overwrite')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Generating an index from 0 to n_stops-1 for stops:\n", "\n", "In RAPTOR, stops are indexed (in an arbitrary order) from 0 to the number of stops minus one. We generate this index below." ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stop_times = spark.read.csv('data/lgpt_guys/stop_times_with_route_int.csv', header=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How many unique routes do we find ?" ] }, { "cell_type": "code", "execution_count": 98, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "1461" ] } ], "source": [ "stop_times.select(stop_times.route_int).dropDuplicates().count()" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------+---------------+\n", "|stop_int|stop_id_general|\n", "+--------+---------------+\n", "| 0| 8502508|\n", "| 1| 8503088|\n", "| 2| 8503078|\n", "| 3| 8591190|\n", "| 4| 8503376|\n", "| 5| 8591284|\n", "| 6| 8589111|\n", "| 7| 8587967|\n", "| 8| 8590819|\n", "| 9| 8591362|\n", "| 10| 8588312|\n", "| 11| 8591149|\n", "| 12| 8591315|\n", "| 13| 8590541|\n", "| 14| 8590804|\n", "| 15| 8591053|\n", "| 16| 8591271|\n", "| 17| 8591085|\n", "| 18| 8591165|\n", "| 19| 8590273|\n", "+--------+---------------+\n", "only showing top 20 rows" ] } ], "source": [ "stops_general_indexed = dfZipWithIndex(stop_times.select(stop_times.stop_id_general).dropDuplicates(),\n", " 0,\n", " 'stop_int')\n", "stops_general_indexed.show()" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stops_general_indexed.write.csv('data/lgpt_guys/stops_general_indexed.csv', header=True, mode='overwrite')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we add this index to `stop_times` and drop columns we won't be using anymore:\n", "- `pickup_type`\n", "- `drop_off_type`\n", "- `departure_hour`\n", "\n", "Note that spark does not maintain order after joins, therefore we will need to reorder stop_times after all the processing is done." ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stops_general_indexed = spark.read.csv('data/lgpt_guys/stops_general_indexed.csv', header=True)" ] }, { "cell_type": "code", "execution_count": 102, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+---------------+--------------------+-------+------------+--------------+-------------+--------------------+-----------+-----------------+---------------+------------+--------------------+---------+----------+--------+\n", "|stop_id_general| trip_id|stop_id|arrival_time|departure_time|stop_sequence| stop_name| route_id| trip_headsign|trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|\n", "+---------------+--------------------+-------+------------+--------------+-------------+--------------------+-----------+-----------------+---------------+------------+--------------------+---------+----------+--------+\n", "| 8591310|535.TA.26-78-j19-...|8591310| 12:25:00| 12:25:00| 3| Zürich, Rautihalde|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 735|\n", "| 8591345|535.TA.26-78-j19-...|8591345| 12:26:00| 12:26:00| 4|Zürich, Schulhaus...|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 1248|\n", "| 8591311|535.TA.26-78-j19-...|8591311| 12:27:00| 12:27:00| 5|Zürich, Rautistrasse|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 748|\n", "| 8591258|535.TA.26-78-j19-...|8591258| 12:29:00| 12:29:00| 6| Zürich, Lindenplatz|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 298|\n", "| 8591097|535.TA.26-78-j19-...|8591097| 12:30:00| 12:30:00| 7|Zürich, Bristenst...|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 1373|\n", "| 8591056|535.TA.26-78-j19-...|8591056| 12:32:00| 12:32:00| 8|Zürich Altstetten...|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 362|\n", "| 8591167|535.TA.26-78-j19-...|8591167| 12:35:00| 12:35:00| 9|Zürich, Grünaustr...|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 766|\n", "| 8591068|535.TA.26-78-j19-...|8591068| 12:36:00| 12:36:00| 10| Zürich, Bändliweg|26-78-j19-1|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 1337|\n", "| 8591116|534.TA.26-78-j19-...|8591116| 12:39:00| 12:39:00| 1|Zürich, Dunkelhölzli|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 30|\n", "| 8591333|534.TA.26-78-j19-...|8591333| 12:39:00| 12:39:00| 2| Zürich, Salzweg|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 624|\n", "| 8591310|534.TA.26-78-j19-...|8591310| 12:40:00| 12:40:00| 3| Zürich, Rautihalde|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 735|\n", "| 8591345|534.TA.26-78-j19-...|8591345| 12:41:00| 12:41:00| 4|Zürich, Schulhaus...|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 1248|\n", "| 8591311|534.TA.26-78-j19-...|8591311| 12:42:00| 12:42:00| 5|Zürich, Rautistrasse|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 748|\n", "| 8591258|534.TA.26-78-j19-...|8591258| 12:44:00| 12:44:00| 6| Zürich, Lindenplatz|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 298|\n", "| 8591097|534.TA.26-78-j19-...|8591097| 12:45:00| 12:45:00| 7|Zürich, Bristenst...|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 1373|\n", "| 8591056|534.TA.26-78-j19-...|8591056| 12:47:00| 12:47:00| 8|Zürich Altstetten...|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 362|\n", "| 8591167|534.TA.26-78-j19-...|8591167| 12:50:00| 12:50:00| 9|Zürich, Grünaustr...|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 766|\n", "| 8591068|534.TA.26-78-j19-...|8591068| 12:51:00| 12:51:00| 10| Zürich, Bändliweg|26-78-j19-1|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 1337|\n", "| 8591116|533.TA.26-78-j19-...|8591116| 12:54:00| 12:54:00| 1|Zürich, Dunkelhölzli|26-78-j19-1|Zürich, Bändliweg| 2807| 0| 12:54:00| 826| 10| 30|\n", "| 8591333|533.TA.26-78-j19-...|8591333| 12:54:00| 12:54:00| 2| Zürich, Salzweg|26-78-j19-1|Zürich, Bändliweg| 2807| 0| 12:54:00| 826| 10| 624|\n", "+---------------+--------------------+-------+------------+--------------+-------------+--------------------+-----------+-----------------+---------------+------------+--------------------+---------+----------+--------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times = stop_times.join(stops_general_indexed, how='inner', on='stop_id_general')\\\n", ".drop('pickup_type', 'drop_off_type', 'departure_hour')\n", "stop_times.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Adding transport types to stop_times from routes.txt" ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+---------+----------------+---------------+----------+----------+\n", "| route_id|agency_id|route_short_name|route_long_name|route_desc|route_type|\n", "+-----------+---------+----------------+---------------+----------+----------+\n", "|11-40-j19-1| 801| 040| null| Bus| 700|\n", "|11-61-j19-1| 7031| 061| null| Bus| 700|\n", "|11-62-j19-1| 7031| 062| null| Bus| 700|\n", "|24-64-j19-1| 801| 064| null| Bus| 700|\n", "|11-83-j19-1| 801| 083| null| Bus| 700|\n", "|1-1-B-j19-1| 11| 1| null| S-Bahn| 400|\n", "|1-1-A-j19-1| 11| 1| null| S-Bahn| 400|\n", "|1-1-C-j19-1| 723| 1| null| Bus| 700|\n", "|1-1-D-j19-1| 840| 1| null| Bus| 700|\n", "|1-1-E-j19-1| 886| 1| null| Bus| 700|\n", "| 1-1-j19-1| 11| 1| null| Intercity| 102|\n", "| 4-1-j19-1| 11| 1| null| S-Bahn| 400|\n", "| 5-1-j19-1| 823| 1| null| Tram| 900|\n", "|6-1-A-j19-1| 146| 1| null| Bus| 700|\n", "|6-1-B-j19-1| 33| 1| null| S-Bahn| 400|\n", "|6-1-C-j19-1| 801| 1| null| Bus| 700|\n", "|6-1-D-j19-1| 889| 1| null| Bus| 700|\n", "|6-1-E-j19-1| 889| 1| null| Bus| 700|\n", "| 6-1-j19-1| 11| 1| null| Intercity| 102|\n", "|8-1-A-j19-1| 834| 1| null| Bus| 700|\n", "+-----------+---------+----------------+---------------+----------+----------+\n", "only showing top 20 rows" ] } ], "source": [ "routes = spark.read.csv(\"/data/sbb/timetables/csv/routes/2019/05/14/routes.txt\", header=True, sep = \",\")\n", "routes.show()" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+----------+\n", "| route_id|route_desc|\n", "+-----------+----------+\n", "|11-40-j19-1| Bus|\n", "|11-61-j19-1| Bus|\n", "|11-62-j19-1| Bus|\n", "|24-64-j19-1| Bus|\n", "|11-83-j19-1| Bus|\n", "|1-1-B-j19-1| S-Bahn|\n", "|1-1-A-j19-1| S-Bahn|\n", "|1-1-C-j19-1| Bus|\n", "|1-1-D-j19-1| Bus|\n", "|1-1-E-j19-1| Bus|\n", "| 1-1-j19-1| Intercity|\n", "| 4-1-j19-1| S-Bahn|\n", "| 5-1-j19-1| Tram|\n", "|6-1-A-j19-1| Bus|\n", "|6-1-B-j19-1| S-Bahn|\n", "|6-1-C-j19-1| Bus|\n", "|6-1-D-j19-1| Bus|\n", "|6-1-E-j19-1| Bus|\n", "| 6-1-j19-1| Intercity|\n", "|8-1-A-j19-1| Bus|\n", "+-----------+----------+\n", "only showing top 20 rows" ] } ], "source": [ "routes_for_join = routes.select(routes.route_id, routes.route_desc)\n", "routes_for_join.show()" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-----------+---------------+--------------------+-------+------------+--------------+-------------+--------------------+-----------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "| route_id|stop_id_general| trip_id|stop_id|arrival_time|departure_time|stop_sequence| stop_name| trip_headsign|trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|\n", "+-----------+---------------+--------------------+-------+------------+--------------+-------------+--------------------+-----------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "|26-78-j19-1| 8591310|535.TA.26-78-j19-...|8591310| 12:25:00| 12:25:00| 3| Zürich, Rautihalde|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 735| Bus|\n", "|26-78-j19-1| 8591345|535.TA.26-78-j19-...|8591345| 12:26:00| 12:26:00| 4|Zürich, Schulhaus...|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 1248| Bus|\n", "|26-78-j19-1| 8591311|535.TA.26-78-j19-...|8591311| 12:27:00| 12:27:00| 5|Zürich, Rautistrasse|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 748| Bus|\n", "|26-78-j19-1| 8591258|535.TA.26-78-j19-...|8591258| 12:29:00| 12:29:00| 6| Zürich, Lindenplatz|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 298| Bus|\n", "|26-78-j19-1| 8591097|535.TA.26-78-j19-...|8591097| 12:30:00| 12:30:00| 7|Zürich, Bristenst...|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 1373| Bus|\n", "|26-78-j19-1| 8591056|535.TA.26-78-j19-...|8591056| 12:32:00| 12:32:00| 8|Zürich Altstetten...|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 362| Bus|\n", "|26-78-j19-1| 8591167|535.TA.26-78-j19-...|8591167| 12:35:00| 12:35:00| 9|Zürich, Grünaustr...|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 766| Bus|\n", "|26-78-j19-1| 8591068|535.TA.26-78-j19-...|8591068| 12:36:00| 12:36:00| 10| Zürich, Bändliweg|Zürich, Bändliweg| 2812| 0| 12:24:00| 826| 10| 1337| Bus|\n", "|26-78-j19-1| 8591116|534.TA.26-78-j19-...|8591116| 12:39:00| 12:39:00| 1|Zürich, Dunkelhölzli|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 30| Bus|\n", "|26-78-j19-1| 8591333|534.TA.26-78-j19-...|8591333| 12:39:00| 12:39:00| 2| Zürich, Salzweg|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 624| Bus|\n", "|26-78-j19-1| 8591310|534.TA.26-78-j19-...|8591310| 12:40:00| 12:40:00| 3| Zürich, Rautihalde|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 735| Bus|\n", "|26-78-j19-1| 8591345|534.TA.26-78-j19-...|8591345| 12:41:00| 12:41:00| 4|Zürich, Schulhaus...|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 1248| Bus|\n", "|26-78-j19-1| 8591311|534.TA.26-78-j19-...|8591311| 12:42:00| 12:42:00| 5|Zürich, Rautistrasse|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 748| Bus|\n", "|26-78-j19-1| 8591258|534.TA.26-78-j19-...|8591258| 12:44:00| 12:44:00| 6| Zürich, Lindenplatz|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 298| Bus|\n", "|26-78-j19-1| 8591097|534.TA.26-78-j19-...|8591097| 12:45:00| 12:45:00| 7|Zürich, Bristenst...|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 1373| Bus|\n", "|26-78-j19-1| 8591056|534.TA.26-78-j19-...|8591056| 12:47:00| 12:47:00| 8|Zürich Altstetten...|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 362| Bus|\n", "|26-78-j19-1| 8591167|534.TA.26-78-j19-...|8591167| 12:50:00| 12:50:00| 9|Zürich, Grünaustr...|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 766| Bus|\n", "|26-78-j19-1| 8591068|534.TA.26-78-j19-...|8591068| 12:51:00| 12:51:00| 10| Zürich, Bändliweg|Zürich, Bändliweg| 2811| 0| 12:39:00| 826| 10| 1337| Bus|\n", "|26-78-j19-1| 8591116|533.TA.26-78-j19-...|8591116| 12:54:00| 12:54:00| 1|Zürich, Dunkelhölzli|Zürich, Bändliweg| 2807| 0| 12:54:00| 826| 10| 30| Bus|\n", "|26-78-j19-1| 8591333|533.TA.26-78-j19-...|8591333| 12:54:00| 12:54:00| 2| Zürich, Salzweg|Zürich, Bändliweg| 2807| 0| 12:54:00| 826| 10| 624| Bus|\n", "+-----------+---------------+--------------------+-------+------------+--------------+-------------+--------------------+-----------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times = stop_times.join(routes_for_join, how='inner', on='route_id')\n", "stop_times.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## VERY IMPORTANT: final sort before saving to csv" ] }, { "cell_type": "code", "execution_count": 106, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "+-------------+---------------+------------------------+-------+------------+--------------+-------------+------------------------------+---------------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "|route_id |stop_id_general|trip_id |stop_id|arrival_time|departure_time|stop_sequence|stop_name |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|\n", "+-------------+---------------+------------------------+-------+------------+--------------+-------------+------------------------------+---------------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "|26-10-j19-1 |8573205 |1672.TA.26-10-j19-1.11.R|8573205|07:00:00 |07:01:00 |27 |Zürich Flughafen, Bahnhof |Zürich Flughafen, Fracht |4096 |1 |07:01:00 |0 |2 |300 |Tram |\n", "|26-10-j19-1 |8588553 |1672.TA.26-10-j19-1.11.R|8588553|07:02:00 |07:02:00 |28 |Zürich Flughafen, Fracht |Zürich Flughafen, Fracht |4096 |1 |07:01:00 |0 |2 |1294 |Tram |\n", "|26-11-A-j19-1|8591049 |791.TA.26-11-A-j19-1.3.H|8591049|19:49:00 |19:49:00 |1 |Zürich, Auzelg |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |1117 |Tram |\n", "|26-11-A-j19-1|8591128 |791.TA.26-11-A-j19-1.3.H|8591128|19:51:00 |19:51:00 |2 |Zürich, Fernsehstudio |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |148 |Tram |\n", "|26-11-A-j19-1|8591830 |791.TA.26-11-A-j19-1.3.H|8591830|19:52:00 |19:52:00 |3 |Glattpark, Glattpark |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |670 |Tram |\n", "|26-11-A-j19-1|8591294 |791.TA.26-11-A-j19-1.3.H|8591294|19:53:00 |19:53:00 |4 |Zürich, Oerlikerhus |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |569 |Tram |\n", "|26-11-A-j19-1|8591256 |791.TA.26-11-A-j19-1.3.H|8591256|19:54:00 |19:54:00 |5 |Zürich, Leutschenbach |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |443 |Tram |\n", "|26-11-A-j19-1|8591273 |791.TA.26-11-A-j19-1.3.H|8591273|19:55:00 |19:55:00 |6 |Zürich, Messe/Hallenstadion |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |388 |Tram |\n", "|26-11-A-j19-1|8591382 |791.TA.26-11-A-j19-1.3.H|8591382|19:57:00 |19:57:00 |7 |Zürich, Sternen Oerlikon |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |686 |Tram |\n", "|26-11-A-j19-1|8580449 |791.TA.26-11-A-j19-1.3.H|8580449|19:59:00 |19:59:00 |8 |Zürich Oerlikon, Bahnhof |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |767 |Tram |\n", "|26-304-j19-1 |8591057 |159.TA.26-304-j19-1.4.R |8591057|19:39:00 |19:39:00 |1 |Zürich Altstetten, Bahnhof N |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |519 |Bus |\n", "|26-304-j19-1 |8591402 |159.TA.26-304-j19-1.4.R |8591402|19:41:00 |19:41:00 |2 |Zürich, Tüffenwies |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |999 |Bus |\n", "|26-304-j19-1 |8591434 |159.TA.26-304-j19-1.4.R |8591434|19:41:00 |19:41:00 |3 |Zürich, Winzerhalde |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |710 |Bus |\n", "|26-304-j19-1 |8591197 |159.TA.26-304-j19-1.4.R |8591197|19:42:00 |19:42:00 |4 |Zürich, Hohenklingensteig |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1124 |Bus |\n", "|26-304-j19-1 |8591436 |159.TA.26-304-j19-1.4.R |8591436|19:43:00 |19:43:00 |5 |Zürich, Winzerstrasse Süd |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |146 |Bus |\n", "|26-304-j19-1 |8591136 |159.TA.26-304-j19-1.4.R |8591136|19:46:00 |19:46:00 |6 |Zürich, Frankental |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |687 |Bus |\n", "|26-304-j19-1 |8590725 |159.TA.26-304-j19-1.4.R |8590725|19:47:00 |19:47:00 |7 |Oberengstringen, Eggbühl |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1328 |Bus |\n", "|26-304-j19-1 |8590726 |159.TA.26-304-j19-1.4.R |8590726|19:48:00 |19:48:00 |8 |Oberengstringen, Lanzrain |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |764 |Bus |\n", "|26-304-j19-1 |8590728 |159.TA.26-304-j19-1.4.R |8590728|19:49:00 |19:49:00 |9 |Oberengstringen, Zentrum |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |375 |Bus |\n", "|26-304-j19-1 |8590727 |159.TA.26-304-j19-1.4.R |8590727|19:50:00 |19:50:00 |10 |Oberengstringen, Paradies |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |737 |Bus |\n", "|26-304-j19-1 |8590833 |159.TA.26-304-j19-1.4.R |8590833|19:51:00 |19:51:00 |11 |Unterengstringen, Langacher |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |761 |Bus |\n", "|26-304-j19-1 |8594732 |159.TA.26-304-j19-1.4.R |8594732|19:53:00 |19:53:00 |12 |Unterengstringen, Sennenbüel N|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |990 |Bus |\n", "|26-304-j19-1 |8590831 |159.TA.26-304-j19-1.4.R |8590831|19:53:00 |19:53:00 |13 |Unterengstringen, Aegelsee |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |502 |Bus |\n", "|26-304-j19-1 |8590911 |159.TA.26-304-j19-1.4.R |8590911|19:55:00 |19:55:00 |14 |Weiningen ZH, Ausserdorf |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |754 |Bus |\n", "|26-304-j19-1 |8590913 |159.TA.26-304-j19-1.4.R |8590913|19:56:00 |19:56:00 |15 |Weiningen ZH, Lindenplatz |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |932 |Bus |\n", "|26-304-j19-1 |8590914 |159.TA.26-304-j19-1.4.R |8590914|19:57:00 |19:57:00 |16 |Weiningen ZH, Schulhaus |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |623 |Bus |\n", "|26-304-j19-1 |8590617 |159.TA.26-304-j19-1.4.R |8590617|19:59:00 |19:59:00 |17 |Geroldswil, Welbrig |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |856 |Bus |\n", "|26-61-j19-1 |8591281 |269.TA.26-61-j19-1.1.H |8591281|19:57:00 |19:57:00 |1 |Zürich, Mühlacker |Zürich, Schwamendingerplatz|2076 |0 |19:57:00 |3 |2 |207 |Bus |\n", "|26-61-j19-1 |8591046 |269.TA.26-61-j19-1.1.H |8591046|19:58:00 |19:58:00 |2 |Zürich, Aspholz |Zürich, Schwamendingerplatz|2076 |0 |19:57:00 |3 |2 |1000 |Bus |\n", "|26-13-j19-1 |8576240 |2064.TA.26-13-j19-1.24.H|8576240|07:00:00 |07:00:00 |5 |Zürich, Meierhofplatz |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1222 |Tram |\n", "|26-13-j19-1 |8591353 |2064.TA.26-13-j19-1.24.H|8591353|07:01:00 |07:01:00 |6 |Zürich, Schwert |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |814 |Tram |\n", "|26-13-j19-1 |8591039 |2064.TA.26-13-j19-1.24.H|8591039|07:02:00 |07:02:00 |7 |Zürich, Alte Trotte |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |774 |Tram |\n", "|26-13-j19-1 |8591121 |2064.TA.26-13-j19-1.24.H|8591121|07:03:00 |07:03:00 |8 |Zürich, Eschergutweg |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |305 |Tram |\n", "|26-13-j19-1 |8591417 |2064.TA.26-13-j19-1.24.H|8591417|07:05:00 |07:05:00 |9 |Zürich, Waidfussweg |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |347 |Tram |\n", "|26-13-j19-1 |8591437 |2064.TA.26-13-j19-1.24.H|8591437|07:06:00 |07:06:00 |10 |Zürich, Wipkingerplatz |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1014 |Tram |\n", "|26-13-j19-1 |8580522 |2064.TA.26-13-j19-1.24.H|8580522|07:08:00 |07:08:00 |11 |Zürich, Escher-Wyss-Platz |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |454 |Tram |\n", "|26-13-j19-1 |8591110 |2064.TA.26-13-j19-1.24.H|8591110|07:09:00 |07:09:00 |12 |Zürich, Dammweg |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1101 |Tram |\n", "|26-13-j19-1 |8591306 |2064.TA.26-13-j19-1.24.H|8591306|07:10:00 |07:10:00 |13 |Zürich, Quellenstrasse |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |789 |Tram |\n", "|26-13-j19-1 |8591257 |2064.TA.26-13-j19-1.24.H|8591257|07:11:00 |07:11:00 |14 |Zürich, Limmatplatz |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |389 |Tram |\n", "|26-13-j19-1 |8591282 |2064.TA.26-13-j19-1.24.H|8591282|07:12:00 |07:12:00 |15 |Zürich, Museum für Gestaltung |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |138 |Tram |\n", "|26-13-j19-1 |8591368 |2064.TA.26-13-j19-1.24.H|8591368|07:14:00 |07:14:00 |16 |Zürich, Sihlquai/HB |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |883 |Tram |\n", "|26-13-j19-1 |8587349 |2064.TA.26-13-j19-1.24.H|8587349|07:16:00 |07:16:00 |17 |Zürich, Bahnhofquai/HB |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |602 |Tram |\n", "|26-13-j19-1 |8591067 |2064.TA.26-13-j19-1.24.H|8591067|07:18:00 |07:18:00 |18 |Zürich, Bahnhofstrasse/HB |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |614 |Tram |\n", "|26-13-j19-1 |8591316 |2064.TA.26-13-j19-1.24.H|8591316|07:20:00 |07:20:00 |19 |Zürich, Rennweg |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |371 |Tram |\n", "|26-13-j19-1 |8591299 |2064.TA.26-13-j19-1.24.H|8591299|07:22:00 |07:22:00 |20 |Zürich, Paradeplatz |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1221 |Tram |\n", "|26-13-j19-1 |8591384 |2064.TA.26-13-j19-1.24.H|8591384|07:23:00 |07:23:00 |21 |Zürich, Stockerstrasse |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |871 |Tram |\n", "|26-13-j19-1 |8591404 |2064.TA.26-13-j19-1.24.H|8591404|07:24:00 |07:24:00 |22 |Zürich, Tunnelstrasse |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |889 |Tram |\n", "|26-13-j19-1 |8591059 |2064.TA.26-13-j19-1.24.H|8591059|07:25:00 |07:25:00 |23 |Zürich Enge, Bahnhof/Bederstr.|Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |175 |Tram |\n", "|26-13-j19-1 |8591415 |2064.TA.26-13-j19-1.24.H|8591415|07:27:00 |07:27:00 |24 |Zürich, Waffenplatzstrasse |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1265 |Tram |\n", "|26-13-j19-1 |8591366 |2064.TA.26-13-j19-1.24.H|8591366|07:28:00 |07:28:00 |25 |Zürich, Sihlcity Nord |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |968 |Tram |\n", "|26-13-j19-1 |8591329 |2064.TA.26-13-j19-1.24.H|8591329|07:29:00 |07:29:00 |26 |Zürich, Saalsporthalle |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1239 |Tram |\n", "|26-13-j19-1 |8591245 |2064.TA.26-13-j19-1.24.H|8591245|07:30:00 |07:30:00 |27 |Zürich, Laubegg |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1215 |Tram |\n", "|26-13-j19-1 |8591405 |2064.TA.26-13-j19-1.24.H|8591405|07:32:00 |07:32:00 |28 |Zürich, Uetlihof |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |847 |Tram |\n", "|26-13-j19-1 |8591385 |2064.TA.26-13-j19-1.24.H|8591385|07:33:00 |07:33:00 |29 |Zürich, Strassenverkehrsamt |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |274 |Tram |\n", "|26-13-j19-1 |8591034 |2064.TA.26-13-j19-1.24.H|8591034|07:34:00 |07:34:00 |30 |Zürich, Albisgütli |Zürich, Albisgütli |1831 |0 |07:00:00 |4 |26 |1351 |Tram |\n", "|26-70-A-j19-1|8591061 |966.TA.26-70-A-j19-1.5.H|8591061|07:00:00 |07:00:00 |9 |Zürich Leimbach, Bahnhof |Zürich, Mittelleimbach |3928 |0 |07:00:00 |5 |5 |1207 |Bus |\n", "|26-70-A-j19-1|8591270 |966.TA.26-70-A-j19-1.5.H|8591270|07:02:00 |07:02:00 |10 |Zürich, Marbachweg |Zürich, Mittelleimbach |3928 |0 |07:00:00 |5 |5 |1200 |Bus |\n", "|26-70-A-j19-1|8591210 |966.TA.26-70-A-j19-1.5.H|8591210|07:03:00 |07:03:00 |11 |Zürich, Im Hüsli |Zürich, Mittelleimbach |3928 |0 |07:00:00 |5 |5 |728 |Bus |\n", "|26-70-A-j19-1|8591370 |966.TA.26-70-A-j19-1.5.H|8591370|07:03:00 |07:03:00 |12 |Zürich, Sihlweidstrasse |Zürich, Mittelleimbach |3928 |0 |07:00:00 |5 |5 |991 |Bus |\n", "|26-70-A-j19-1|8591278 |966.TA.26-70-A-j19-1.5.H|8591278|07:04:00 |07:04:00 |13 |Zürich, Mittelleimbach |Zürich, Mittelleimbach |3928 |0 |07:00:00 |5 |5 |141 |Bus |\n", "|26-703-j19-1 |8591825 |179.TA.26-703-j19-1.2.R |8591825|07:10:00 |07:10:00 |1 |Benglen, Bodenacher |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |584 |Bus |\n", "|26-703-j19-1 |8590504 |179.TA.26-703-j19-1.2.R |8590504|07:11:00 |07:11:00 |2 |Benglen, Gerlisbrunnen |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |863 |Bus |\n", "|26-703-j19-1 |8596005 |179.TA.26-703-j19-1.2.R |8596005|07:14:00 |07:14:00 |3 |Binz bei Maur, Twäracher |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |1369 |Bus |\n", "|26-703-j19-1 |8591832 |179.TA.26-703-j19-1.2.R |8591832|07:14:00 |07:14:00 |4 |Pfaffhausen, Müseren |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |1024 |Bus |\n", "|26-703-j19-1 |8591147 |179.TA.26-703-j19-1.2.R |8591147|07:16:00 |07:16:00 |5 |Zürich, Friedhof Witikon |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |1260 |Bus |\n", "|26-703-j19-1 |8591162 |179.TA.26-703-j19-1.2.R |8591162|07:17:00 |07:17:00 |6 |Zürich, Glockenacker |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |150 |Bus |\n", "|26-703-j19-1 |8591261 |179.TA.26-703-j19-1.2.R |8591261|07:18:00 |07:18:00 |7 |Zürich, Loorenstrasse |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |1198 |Bus |\n", "|26-703-j19-1 |8591107 |179.TA.26-703-j19-1.2.R |8591107|07:19:00 |07:19:00 |8 |Zürich, Carl-Spitteler-Strasse|Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |1313 |Bus |\n", "|26-703-j19-1 |8591233 |179.TA.26-703-j19-1.2.R |8591233|07:25:00 |07:25:00 |9 |Zürich, Klusplatz |Zürich, Klusplatz |9385 |1 |07:10:00 |6 |9 |1133 |Bus |\n", "|26-703-j19-1 |8591825 |171.TA.26-703-j19-1.2.R |8591825|07:12:00 |07:12:00 |1 |Benglen, Bodenacher |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |584 |Bus |\n", "|26-703-j19-1 |8590504 |171.TA.26-703-j19-1.2.R |8590504|07:13:00 |07:13:00 |2 |Benglen, Gerlisbrunnen |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |863 |Bus |\n", "|26-703-j19-1 |8596005 |171.TA.26-703-j19-1.2.R |8596005|07:16:00 |07:16:00 |3 |Binz bei Maur, Twäracher |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |1369 |Bus |\n", "|26-703-j19-1 |8591832 |171.TA.26-703-j19-1.2.R |8591832|07:16:00 |07:16:00 |4 |Pfaffhausen, Müseren |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |1024 |Bus |\n", "|26-703-j19-1 |8591147 |171.TA.26-703-j19-1.2.R |8591147|07:18:00 |07:18:00 |5 |Zürich, Friedhof Witikon |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |1260 |Bus |\n", "|26-703-j19-1 |8591162 |171.TA.26-703-j19-1.2.R |8591162|07:19:00 |07:19:00 |6 |Zürich, Glockenacker |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |150 |Bus |\n", "|26-703-j19-1 |8591261 |171.TA.26-703-j19-1.2.R |8591261|07:20:00 |07:20:00 |7 |Zürich, Loorenstrasse |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |1198 |Bus |\n", "|26-703-j19-1 |8591107 |171.TA.26-703-j19-1.2.R |8591107|07:21:00 |07:21:00 |8 |Zürich, Carl-Spitteler-Strasse|Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |1313 |Bus |\n", "|26-703-j19-1 |8591233 |171.TA.26-703-j19-1.2.R |8591233|07:27:00 |07:27:00 |9 |Zürich, Klusplatz |Zürich, Klusplatz |9346 |1 |07:12:00 |6 |9 |1133 |Bus |\n", "|26-703-j19-1 |8591825 |155.TA.26-703-j19-1.2.R |8591825|07:25:00 |07:25:00 |1 |Benglen, Bodenacher |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |584 |Bus |\n", "|26-703-j19-1 |8590504 |155.TA.26-703-j19-1.2.R |8590504|07:26:00 |07:26:00 |2 |Benglen, Gerlisbrunnen |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |863 |Bus |\n", "|26-703-j19-1 |8596005 |155.TA.26-703-j19-1.2.R |8596005|07:29:00 |07:29:00 |3 |Binz bei Maur, Twäracher |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |1369 |Bus |\n", "|26-703-j19-1 |8591832 |155.TA.26-703-j19-1.2.R |8591832|07:29:00 |07:29:00 |4 |Pfaffhausen, Müseren |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |1024 |Bus |\n", "|26-703-j19-1 |8591147 |155.TA.26-703-j19-1.2.R |8591147|07:31:00 |07:31:00 |5 |Zürich, Friedhof Witikon |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |1260 |Bus |\n", "|26-703-j19-1 |8591162 |155.TA.26-703-j19-1.2.R |8591162|07:32:00 |07:32:00 |6 |Zürich, Glockenacker |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |150 |Bus |\n", "|26-703-j19-1 |8591261 |155.TA.26-703-j19-1.2.R |8591261|07:33:00 |07:33:00 |7 |Zürich, Loorenstrasse |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |1198 |Bus |\n", "|26-703-j19-1 |8591107 |155.TA.26-703-j19-1.2.R |8591107|07:34:00 |07:34:00 |8 |Zürich, Carl-Spitteler-Strasse|Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |1313 |Bus |\n", "|26-703-j19-1 |8591233 |155.TA.26-703-j19-1.2.R |8591233|07:40:00 |07:40:00 |9 |Zürich, Klusplatz |Zürich, Klusplatz |9267 |1 |07:25:00 |6 |9 |1133 |Bus |\n", "|26-703-j19-1 |8591825 |144.TA.26-703-j19-1.2.R |8591825|07:27:00 |07:27:00 |1 |Benglen, Bodenacher |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |584 |Bus |\n", "|26-703-j19-1 |8590504 |144.TA.26-703-j19-1.2.R |8590504|07:28:00 |07:28:00 |2 |Benglen, Gerlisbrunnen |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |863 |Bus |\n", "|26-703-j19-1 |8596005 |144.TA.26-703-j19-1.2.R |8596005|07:31:00 |07:31:00 |3 |Binz bei Maur, Twäracher |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |1369 |Bus |\n", "|26-703-j19-1 |8591832 |144.TA.26-703-j19-1.2.R |8591832|07:31:00 |07:31:00 |4 |Pfaffhausen, Müseren |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |1024 |Bus |\n", "|26-703-j19-1 |8591147 |144.TA.26-703-j19-1.2.R |8591147|07:33:00 |07:33:00 |5 |Zürich, Friedhof Witikon |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |1260 |Bus |\n", "|26-703-j19-1 |8591162 |144.TA.26-703-j19-1.2.R |8591162|07:34:00 |07:34:00 |6 |Zürich, Glockenacker |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |150 |Bus |\n", "|26-703-j19-1 |8591261 |144.TA.26-703-j19-1.2.R |8591261|07:35:00 |07:35:00 |7 |Zürich, Loorenstrasse |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |1198 |Bus |\n", "|26-703-j19-1 |8591107 |144.TA.26-703-j19-1.2.R |8591107|07:36:00 |07:36:00 |8 |Zürich, Carl-Spitteler-Strasse|Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |1313 |Bus |\n", "|26-703-j19-1 |8591233 |144.TA.26-703-j19-1.2.R |8591233|07:42:00 |07:42:00 |9 |Zürich, Klusplatz |Zürich, Klusplatz |9231 |1 |07:27:00 |6 |9 |1133 |Bus |\n", "|26-703-j19-1 |8591825 |120.TA.26-703-j19-1.2.R |8591825|07:40:00 |07:40:00 |1 |Benglen, Bodenacher |Zürich, Klusplatz |9159 |1 |07:40:00 |6 |9 |584 |Bus |\n", "|26-703-j19-1 |8590504 |120.TA.26-703-j19-1.2.R |8590504|07:41:00 |07:41:00 |2 |Benglen, Gerlisbrunnen |Zürich, Klusplatz |9159 |1 |07:40:00 |6 |9 |863 |Bus |\n", "|26-703-j19-1 |8596005 |120.TA.26-703-j19-1.2.R |8596005|07:44:00 |07:44:00 |3 |Binz bei Maur, Twäracher |Zürich, Klusplatz |9159 |1 |07:40:00 |6 |9 |1369 |Bus |\n", "|26-703-j19-1 |8591832 |120.TA.26-703-j19-1.2.R |8591832|07:44:00 |07:44:00 |4 |Pfaffhausen, Müseren |Zürich, Klusplatz |9159 |1 |07:40:00 |6 |9 |1024 |Bus |\n", "+-------------+---------------+------------------------+-------+------------+--------------+-------------+------------------------------+---------------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "only showing top 100 rows" ] } ], "source": [ "stop_times = stop_times.sort(stop_times.route_int.cast('int'), \n", " stop_times.departure_first_stop, \n", " stop_times.trip_id, \n", " stop_times.stop_sequence.cast('int'))\n", "stop_times.show(100, 0)" ] }, { "cell_type": "code", "execution_count": 107, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stop_times.write.csv('data/lgpt_guys/stop_times_final_cyril.csv', header=True, mode = 'overwrite')" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Verifying a few routes and trips on real data" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "stop_times = spark.read.csv('data/lgpt_guys/stop_times_final_cyril.csv', header=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+------------+---------------+-----------------------+-------+------------+--------------+-------------+------------------------------+--------------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", + "|route_id |stop_id_general|trip_id |stop_id|arrival_time|departure_time|stop_sequence|stop_name |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|\n", + "+------------+---------------+-----------------------+-------+------------+--------------+-------------+------------------------------+--------------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", + "|26-660-j19-1|8576167 |486.TA.26-660-j19-1.9.R|8576167|07:16:00 |07:16:00 |1 |Nürensdorf, Chrüzstrass |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |1197 |Bus |\n", + "|26-660-j19-1|8576168 |486.TA.26-660-j19-1.9.R|8576168|07:17:00 |07:17:00 |2 |Birchwil (Nürensdorf) |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |640 |Bus |\n", + "|26-660-j19-1|8576169 |486.TA.26-660-j19-1.9.R|8576169|07:19:00 |07:19:00 |3 |Nürensdorf, Oberwil |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |862 |Bus |\n", + "|26-660-j19-1|8576172 |486.TA.26-660-j19-1.9.R|8576172|07:22:00 |07:22:00 |4 |Breite b. N'dorf,Grünenwaldstr|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |42 |Bus |\n", + "|26-660-j19-1|8576174 |486.TA.26-660-j19-1.9.R|8576174|07:24:00 |07:24:00 |5 |Brütten, Hofacher |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |93 |Bus |\n", + "|26-660-j19-1|8506960 |486.TA.26-660-j19-1.9.R|8506960|07:26:00 |07:26:00 |6 |Brütten, Zentrum |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |1059 |Bus |\n", + "|26-660-j19-1|8576176 |486.TA.26-660-j19-1.9.R|8576176|07:27:00 |07:27:00 |7 |Brütten, Harossen |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |775 |Bus |\n", + "|26-660-j19-1|8591835 |486.TA.26-660-j19-1.9.R|8591835|07:27:00 |07:27:00 |8 |Brütten, Steighof |Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |1129 |Bus |\n", + "+------------+---------------+-----------------------+-------+------------+--------------+-------------+------------------------------+--------------------------+---------------+------------+--------------------+---------+----------+--------+----------+" + ] + } + ], + "source": [ + "stop_times.where(stop_times.route_int==500).show(100, 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Validated on sbb.ch" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "FloatProgress(value=0.0, bar_style='info', description='Progress:', layout=Layout(height='25px', width='50%'),…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "+------------+---------------+----------------------+-------+------------+--------------+-------------+------------------------+---------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", + "|route_id |stop_id_general|trip_id |stop_id|arrival_time|departure_time|stop_sequence|stop_name |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|\n", + "+------------+---------------+----------------------+-------+------------+--------------+-------------+------------------------+---------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", + "|26-766-j19-1|8503700 |11.TA.26-766-j19-1.2.H|8503700|07:23:00 |07:23:00 |1 |Bassersdorf, Bahnhof |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |218 |Bus |\n", + "|26-766-j19-1|8576160 |11.TA.26-766-j19-1.2.H|8576160|07:25:00 |07:25:00 |2 |Bassersdorf, Löwen |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |1298 |Bus |\n", + "|26-766-j19-1|8590503 |11.TA.26-766-j19-1.2.H|8590503|07:25:00 |07:25:00 |3 |Bassersdorf, Chlupfgasse|Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |507 |Bus |\n", + "|26-766-j19-1|8576158 |11.TA.26-766-j19-1.2.H|8576158|07:26:00 |07:26:00 |4 |Bassersdorf, Talgüetli |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |913 |Bus |\n", + "|26-766-j19-1|8596100 |11.TA.26-766-j19-1.2.H|8596100|07:28:00 |07:28:00 |5 |Bassersdorf, Sportanlage|Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |1226 |Bus |\n", + "|26-766-j19-1|8588315 |11.TA.26-766-j19-1.2.H|8588315|07:29:00 |07:29:00 |6 |Kloten, Grindel |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |290 |Bus |\n", + "|26-766-j19-1|8576155 |11.TA.26-766-j19-1.2.H|8576155|07:30:00 |07:30:00 |7 |Kloten, Grubenstrasse |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |1072 |Bus |\n", + "|26-766-j19-1|8576154 |11.TA.26-766-j19-1.2.H|8576154|07:31:00 |07:31:00 |8 |Kloten, Oberfeld |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |1338 |Bus |\n", + "|26-766-j19-1|8580435 |11.TA.26-766-j19-1.2.H|8580435|07:32:00 |07:32:00 |9 |Kloten, Mühle |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |919 |Bus |\n", + "|26-766-j19-1|8587420 |11.TA.26-766-j19-1.2.H|8587420|07:34:00 |07:34:00 |10 |Kloten, Bahnhof |Kloten, Bahnhof|4946 |0 |07:23:00 |200 |10 |498 |Bus |\n", + "|26-766-j19-1|8503700 |10.TA.26-766-j19-1.2.H|8503700|07:53:00 |07:53:00 |1 |Bassersdorf, Bahnhof |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |218 |Bus |\n", + "|26-766-j19-1|8576160 |10.TA.26-766-j19-1.2.H|8576160|07:55:00 |07:55:00 |2 |Bassersdorf, Löwen |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |1298 |Bus |\n", + "|26-766-j19-1|8590503 |10.TA.26-766-j19-1.2.H|8590503|07:55:00 |07:55:00 |3 |Bassersdorf, Chlupfgasse|Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |507 |Bus |\n", + "|26-766-j19-1|8576158 |10.TA.26-766-j19-1.2.H|8576158|07:56:00 |07:56:00 |4 |Bassersdorf, Talgüetli |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |913 |Bus |\n", + "|26-766-j19-1|8596100 |10.TA.26-766-j19-1.2.H|8596100|07:58:00 |07:58:00 |5 |Bassersdorf, Sportanlage|Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |1226 |Bus |\n", + "|26-766-j19-1|8588315 |10.TA.26-766-j19-1.2.H|8588315|07:59:00 |07:59:00 |6 |Kloten, Grindel |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |290 |Bus |\n", + "|26-766-j19-1|8576155 |10.TA.26-766-j19-1.2.H|8576155|08:00:00 |08:00:00 |7 |Kloten, Grubenstrasse |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |1072 |Bus |\n", + "|26-766-j19-1|8576154 |10.TA.26-766-j19-1.2.H|8576154|08:01:00 |08:01:00 |8 |Kloten, Oberfeld |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |1338 |Bus |\n", + "|26-766-j19-1|8580435 |10.TA.26-766-j19-1.2.H|8580435|08:02:00 |08:02:00 |9 |Kloten, Mühle |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |919 |Bus |\n", + "|26-766-j19-1|8587420 |10.TA.26-766-j19-1.2.H|8587420|08:04:00 |08:04:00 |10 |Kloten, Bahnhof |Kloten, Bahnhof|4899 |0 |07:53:00 |200 |10 |498 |Bus |\n", + "|26-766-j19-1|8503700 |9.TA.26-766-j19-1.2.H |8503700|16:39:00 |16:39:00 |1 |Bassersdorf, Bahnhof |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |218 |Bus |\n", + "|26-766-j19-1|8576160 |9.TA.26-766-j19-1.2.H |8576160|16:41:00 |16:41:00 |2 |Bassersdorf, Löwen |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |1298 |Bus |\n", + "|26-766-j19-1|8590503 |9.TA.26-766-j19-1.2.H |8590503|16:42:00 |16:42:00 |3 |Bassersdorf, Chlupfgasse|Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |507 |Bus |\n", + "|26-766-j19-1|8576158 |9.TA.26-766-j19-1.2.H |8576158|16:43:00 |16:43:00 |4 |Bassersdorf, Talgüetli |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |913 |Bus |\n", + "|26-766-j19-1|8596100 |9.TA.26-766-j19-1.2.H |8596100|16:44:00 |16:44:00 |5 |Bassersdorf, Sportanlage|Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |1226 |Bus |\n", + "|26-766-j19-1|8588315 |9.TA.26-766-j19-1.2.H |8588315|16:45:00 |16:45:00 |6 |Kloten, Grindel |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |290 |Bus |\n", + "|26-766-j19-1|8576155 |9.TA.26-766-j19-1.2.H |8576155|16:46:00 |16:46:00 |7 |Kloten, Grubenstrasse |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |1072 |Bus |\n", + "|26-766-j19-1|8576154 |9.TA.26-766-j19-1.2.H |8576154|16:47:00 |16:47:00 |8 |Kloten, Oberfeld |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |1338 |Bus |\n", + "|26-766-j19-1|8580435 |9.TA.26-766-j19-1.2.H |8580435|16:49:00 |16:49:00 |9 |Kloten, Mühle |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |919 |Bus |\n", + "|26-766-j19-1|8587420 |9.TA.26-766-j19-1.2.H |8587420|16:50:00 |16:50:00 |10 |Kloten, Bahnhof |Kloten, Bahnhof|4853 |0 |16:39:00 |200 |10 |498 |Bus |\n", + "|26-766-j19-1|8503700 |8.TA.26-766-j19-1.2.H |8503700|17:09:00 |17:09:00 |1 |Bassersdorf, Bahnhof |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |218 |Bus |\n", + "|26-766-j19-1|8576160 |8.TA.26-766-j19-1.2.H |8576160|17:11:00 |17:11:00 |2 |Bassersdorf, Löwen |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |1298 |Bus |\n", + "|26-766-j19-1|8590503 |8.TA.26-766-j19-1.2.H |8590503|17:12:00 |17:12:00 |3 |Bassersdorf, Chlupfgasse|Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |507 |Bus |\n", + "|26-766-j19-1|8576158 |8.TA.26-766-j19-1.2.H |8576158|17:13:00 |17:13:00 |4 |Bassersdorf, Talgüetli |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |913 |Bus |\n", + "|26-766-j19-1|8596100 |8.TA.26-766-j19-1.2.H |8596100|17:14:00 |17:14:00 |5 |Bassersdorf, Sportanlage|Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |1226 |Bus |\n", + "|26-766-j19-1|8588315 |8.TA.26-766-j19-1.2.H |8588315|17:15:00 |17:15:00 |6 |Kloten, Grindel |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |290 |Bus |\n", + "|26-766-j19-1|8576155 |8.TA.26-766-j19-1.2.H |8576155|17:16:00 |17:16:00 |7 |Kloten, Grubenstrasse |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |1072 |Bus |\n", + "|26-766-j19-1|8576154 |8.TA.26-766-j19-1.2.H |8576154|17:17:00 |17:17:00 |8 |Kloten, Oberfeld |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |1338 |Bus |\n", + "|26-766-j19-1|8580435 |8.TA.26-766-j19-1.2.H |8580435|17:19:00 |17:19:00 |9 |Kloten, Mühle |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |919 |Bus |\n", + "|26-766-j19-1|8587420 |8.TA.26-766-j19-1.2.H |8587420|17:20:00 |17:20:00 |10 |Kloten, Bahnhof |Kloten, Bahnhof|4805 |0 |17:09:00 |200 |10 |498 |Bus |\n", + "|26-766-j19-1|8503700 |7.TA.26-766-j19-1.2.H |8503700|17:39:00 |17:39:00 |1 |Bassersdorf, Bahnhof |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |218 |Bus |\n", + "|26-766-j19-1|8576160 |7.TA.26-766-j19-1.2.H |8576160|17:41:00 |17:41:00 |2 |Bassersdorf, Löwen |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |1298 |Bus |\n", + "|26-766-j19-1|8590503 |7.TA.26-766-j19-1.2.H |8590503|17:42:00 |17:42:00 |3 |Bassersdorf, Chlupfgasse|Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |507 |Bus |\n", + "|26-766-j19-1|8576158 |7.TA.26-766-j19-1.2.H |8576158|17:43:00 |17:43:00 |4 |Bassersdorf, Talgüetli |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |913 |Bus |\n", + "|26-766-j19-1|8596100 |7.TA.26-766-j19-1.2.H |8596100|17:44:00 |17:44:00 |5 |Bassersdorf, Sportanlage|Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |1226 |Bus |\n", + "|26-766-j19-1|8588315 |7.TA.26-766-j19-1.2.H |8588315|17:45:00 |17:45:00 |6 |Kloten, Grindel |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |290 |Bus |\n", + "|26-766-j19-1|8576155 |7.TA.26-766-j19-1.2.H |8576155|17:46:00 |17:46:00 |7 |Kloten, Grubenstrasse |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |1072 |Bus |\n", + "|26-766-j19-1|8576154 |7.TA.26-766-j19-1.2.H |8576154|17:47:00 |17:47:00 |8 |Kloten, Oberfeld |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |1338 |Bus |\n", + "|26-766-j19-1|8580435 |7.TA.26-766-j19-1.2.H |8580435|17:49:00 |17:49:00 |9 |Kloten, Mühle |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |919 |Bus |\n", + "|26-766-j19-1|8587420 |7.TA.26-766-j19-1.2.H |8587420|17:50:00 |17:50:00 |10 |Kloten, Bahnhof |Kloten, Bahnhof|4758 |0 |17:39:00 |200 |10 |498 |Bus |\n", + "+------------+---------------+----------------------+-------+------------+--------------+-------------+------------------------+---------------+---------------+------------+--------------------+---------+----------+--------+----------+" + ] + } + ], + "source": [ + "stop_times.where(stop_times.route_int==200).show(100, 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Verified on sbb.ch. This one is interesting: the service stops in the middle of the day. That is also what is observed on sbb.ch." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { "display_name": "PySpark", "language": "", "name": "pysparkkernel" }, "language_info": { "codemirror_mode": { "name": "python", "version": 3 }, "mimetype": "text/x-python", "name": "pyspark", "pygments_lexer": "python3" } }, "nbformat": 4, "nbformat_minor": 4 }