{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Generating a cleaned dataset compatible with the RAPTOR file structure\n", "\n", "*Author: Cyril Pulver, with help and boilerplate code from Tomas Turner*\n", "\n", "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 GTFS file `stop_times.txt` formatted to a cleaned GTFS-like `stop_times` table, it is possible to reconstruct everything required to run RAPTOR**. In particular, trips and routes are reconstructed directly from the cleaned `stop_times` table and without insight from the GTFS file `routes.txt`.\n", "\n", "The key idea is to filter out stops not belonging to the 15km radius around Zürich HB, filter out services not running on standard business days and filter out stop times not between 7 am and 8pm. Trimming the data does not really matter to run RAPTOR in itself, but lightens the computational cost of estimating the probability distribution of delays. However, the key stop to run RAPTOR properly is the following: trips from the GTFS file format are grouped in RAPTOR-compatible trips (a sequence of stop times where stops are always served in the same order) based on reconstructed lists of stops served **directly in the cleaned `stop_times` table**. Routes are then constructed by finding trips serving the same sequence of stops.\n", "\n", "Finally, footpaths and associated walking times are estimated from the bird's fly distance between all pairs of stops as defined by GPS coordinates. We only keep footpaths for distances less than 500m, no matter the terrain betwen both stops. Walking times are derived from distances by considering a uniform waking velocity of 50 meters per minute. We only compute walking times between stops that do not share the same parent stop (i.e stops with differing `BPUIC`). Indeed, footpaths within large stations depend largely on station plans themselves and less so on the GPS coordinates of the different platforms. A 2 minute minimum transfer time is enforced directly in the main looop of RAPTOR to account for any connection happening within a single parent station.\n", "\n", "Below, we present a step by step outline of the data wrangling strategy:\n", "\n", "- 1) Filter out stops out of 15km radius around Zürich HB\n", " - Done on the GTFS file `stops.txt`\n", " \n", "\n", "- 2) Give a general stop id to stops by trimming stop_id to the first 7 characters. Has the overall effect of gathering stops sharing a parent stop, but it is more robust to inconcistencies detected in the data. Also, the general stop id corresponds to the BPUIC field in the SBB dataset. That will come handy when mining for information about delays.\n", " - Done on stops (add a `stop_id_general` column)\n", " - Used as an input for stopTimes. At this point, stop_times contains only stops within 15km of ZH HB\n", " \n", " \n", "- 3) Keep only trips belonging to services that run each day of the business week:\n", " - Obtain the list of services from the GTFS file `calendar.txt`\n", " - Serves as an input to filter trips\n", " - Serves as an input to filter `stop_times`\n", " \n", " \n", "- 4) Keep only stop times between 7am and 7pm\n", " - Done directly on `stop_times`\n", " \n", " \n", "- 5) Find unique trips, based on the stops sequence and the departure times sequence. We need to merge trips serving the same stops at the same times each day into a single trip, as the date is not used as an input to RAPTOR.\n", " - sort `stop_times` by trip and stop sequence\n", " - For each trip\n", " - build a list containing the sequence of stops visited (`all_stops`)\n", " - build a list containing all departure times for those stops\n", " - keep only a single trip between those that share the same lists of stops visited and departure times.\n", " - Filter `stop_times` based on said unique trips.\n", " \n", " \n", "- 6) Building routes based on unique trips sharing the same `all_stops` column\n", " - order (at this point unique) trips by `all_stops` and earliest departure time (i.e the departure time from the first stop of the trip)\n", " - group trips by `all_stops` and assign a unique integer `route_int` to each group\n", " - Add this information to `stop_times`\n", " \n", " \n", "- 7) Assigning unique integer indices to stops\n", " - get unique general (parent) stop names from `stop_times`\n", " - assign an integer index `stop_int` from 0 to n_stops-1 with a spark dataframe adapted version of `zipWithIndex`\n", " - Add the `stop_int` to `stop_times`\n", " \n", " \n", "- 8) Getting transport type information (Bus, Tram, Train etc) from the GTFS file `routes.txt`\n", " - inner join `stop_times` with `routes.txt` using `route_id`\n", "\n", "\n", "- 9) Assigning a monotonically increasing index to be able to re-sort `stop_times` by `route_int` and trip as is required in the RAPTOR data structure StopTimes.\n", "\n", "\n", "- 10) Computing footpaths that serve as an input to RAPTOR's Transfers data structure. We only consider stops present in the final and filtered `stop_times` table.\n", " - get all unique `stop_int` with a single pair of coordinates\n", " - cross-join two copies of this dataframe. The result is all permutations of `stop_int` pairs\n", " - drop pairs where `general_stop_id` is the same\n", " - compute the bird's fly distance with geopy for all other pairs of `stop_int` using GPS coordinates\n", " - filter out pairs of stops with a distance greater than 500 meters\n", " - transform distance to walking time in seconds\n", " - order by `stop_int1`, then `stop_int2` to mimic the data structure Transfers in RAPTOR\n", " - create a monotonically increasing ID to easily sort on this table after reading from a distributed file system\n", " \n", " \n", "Executing all the cells in this notebook generates cleaned .csv tables saved on HDFS that serve as an input to the `notebooks/transfer_to_local.ipynb` notebook." ] }, { "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?
7933application_1589299642358_2451pysparkidleLinkLink
7946application_1589299642358_2464pysparkidleLinkLink
7951application_1589299642358_2469pysparkidleLinkLink
7958application_1589299642358_2476pysparkidleLinkLink
7959application_1589299642358_2477pysparkidleLinkLink
7962application_1589299642358_2480pysparkidleLinkLink
7965application_1589299642358_2485pysparkidleLinkLink
7968application_1589299642358_2488pysparkidleLinkLink
7971application_1589299642358_2491pysparkidleLinkLink
7972application_1589299642358_2492pysparkidleLinkLink
7973application_1589299642358_2493pysparkidleLinkLink
7975application_1589299642358_2495pysparkidleLinkLink
7977application_1589299642358_2497pysparkidleLinkLink
7978application_1589299642358_2498pysparkbusyLinkLink
7980application_1589299642358_2501pysparkidleLinkLink
7981application_1589299642358_2502pysparkidleLinkLink
7982application_1589299642358_2503pysparkbusyLinkLink
7983application_1589299642358_2504pysparkidleLinkLink
7984application_1589299642358_2505pysparkbusyLinkLink
" ], "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?
7985application_1589299642358_2506pysparkidleLinkLink
" ], "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": "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| stop_lat| stop_lon|\n", "+-----------+---------------+--------------------+----------------+----------------+\n", "| 8500926| 8500926|Oetwil a.d.L., Sc...|47.4236270123012| 8.4031825286317|\n", "| 8502186| 8502186|Dietikon Stoffelbach|47.3934058321612|8.39894248049007|\n", "|8502186:0:1| 8502186|Dietikon Stoffelbach|47.3934666445388|8.39894248049007|\n", "|8502186:0:2| 8502186|Dietikon Stoffelbach|47.3935274568464|8.39894248049007|\n", "| 8502186P| 8502186|Dietikon Stoffelbach|47.3934058321612|8.39894248049007|\n", "| 8502187| 8502187|Rudolfstetten Hof...|47.3646945560768|8.37709545277724|\n", "|8502187:0:1| 8502187|Rudolfstetten Hof...|47.3647554015789|8.37709545277724|\n", "|8502187:0:2| 8502187|Rudolfstetten Hof...|47.3648162470108|8.37709545277724|\n", "| 8502187P| 8502187|Rudolfstetten Hof...|47.3646945560768|8.37709545277724|\n", "| 8502188| 8502188| Zufikon Hammergut|47.3558347019549|8.35472740219955|\n", "|8502188:0:1| 8502188| Zufikon Hammergut|47.3558955576756|8.35472740219955|\n", "|8502188:0:2| 8502188| Zufikon Hammergut|47.3559564133261|8.35472740219955|\n", "| 8502188P| 8502188| Zufikon Hammergut|47.3558347019549|8.35472740219955|\n", "| 8502208| 8502208| Horgen Oberdorf|47.2587475534877|8.58979854578067|\n", "|8502208:0:2| 8502208| Horgen Oberdorf|47.2589304560815|8.58979854578067|\n", "|8502208:0:3| 8502208| Horgen Oberdorf|47.2588085210892|8.58979854578067|\n", "|8502208:0:4| 8502208| Horgen Oberdorf|47.2588694886204|8.58979854578067|\n", "| 8502208P| 8502208| Horgen Oberdorf|47.2587475534877|8.58979854578067|\n", "| 8502209| 8502209| Oberrieden Dorf|47.2767238569466| 8.577635356832|\n", "|8502209:0:1| 8502209| Oberrieden Dorf|47.2768457506749| 8.577635356832|\n", "+-----------+---------------+--------------------+----------------+----------------+\n", "only showing top 20 rows" ] } ], "source": [ "stops_15km_for_join = stops_15km.select(stops_15km.stop_id, \n", " stops_15km.stop_id_general, \n", " stops.stop_name, \n", " stops.stop_lat, \n", " stops.stop_lon)\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| stop_lat| stop_lon|\n", "+-----------+--------------------+------------+--------------+-------------+-----------+-------------+---------------+-------------------+----------------+----------------+\n", "|8503202:0:5|61.TA.25-75-j19-1...| 15:12:00| 15:14:00| 5| 0| 0| 8503202| Thalwil|47.2962171893553|8.56475351565593|\n", "|8503202:0:5|99.TA.25-75-j19-1...| 19:14:00| 19:15:00| 5| 0| 0| 8503202| Thalwil|47.2962171893553|8.56475351565593|\n", "|8503202:0:5|137.TA.25-75-j19-...| 23:12:00| 23:14:00| 5| 0| 0| 8503202| Thalwil|47.2962171893553|8.56475351565593|\n", "|8503000:0:6|287.TA.25-75-j19-...| 19:35:00| 19:35:00| 1| 0| 0| 8503000| Zürich HB|47.3786628415821|8.54019357578468|\n", "|8503000:0:7|337.TA.25-75-j19-...| 22:35:00| 22:35:00| 1| 0| 0| 8503000| Zürich HB|47.3787236709708|8.54019357578468|\n", "| 8587860|8.TA.26-811-j19-1...| 23:38:00| 23:38:00| 9| 0| 0| 8587860| Uster, Strick|47.3564493415083|8.71275994188806|\n", "| 8588052|35.TA.26-811-j19-...| 06:48:00| 06:48:00| 4| 0| 0| 8588052| Uster, Gschwader|47.3582688760385|8.71277790819375|\n", "| 8588052|38.TA.26-811-j19-...| 18:33:00| 18:33:00| 4| 0| 0| 8588052| Uster, Gschwader|47.3582688760385|8.71277790819375|\n", "| 8573504|42.TA.26-811-j19-...| 06:30:00| 06:30:00| 1| 0| 0| 8573504| Uster, Bahnhof|47.3511851173852|8.71683829327853|\n", "| 8573504|98.TA.26-811-j19-...| 15:15:00| 15:15:00| 1| 0| 0| 8573504| Uster, Bahnhof|47.3511851173852|8.71683829327853|\n", "| 8503152|133.TA.26-811-j19...| 17:51:00| 17:51:00| 7| 0| 0| 8503152|Uster, Brandschenke|47.3611410570261|8.71073873249851|\n", "| 8588050|27.TA.26-812-j19-...| 20:05:00| 20:05:00| 7| 0| 0| 8588050| Uster, Bordacker|47.3519945640447|8.72933385888238|\n", "| 8588051|35.TA.26-812-j19-...| 09:30:00| 09:30:00| 2| 0| 0| 8588051| Uster, Dammstrasse|47.3534491024058|8.71567946656186|\n", "| 8588059|61.TA.26-812-j19-...| 06:04:00| 06:04:00| 6| 0| 0| 8588059| Uster, Weidli| 47.353996826126|8.73063641604453|\n", "| 8503567|66.TA.26-812-j19-...| 06:17:00| 06:17:00| 3| 0| 0| 8503567| Uster, Spital|47.3538507670231|8.72349480953479|\n", "| 8503567|105.TA.26-812-j19...| 08:32:00| 08:32:00| 3| 0| 0| 8503567| Uster, Spital|47.3538507670231|8.72349480953479|\n", "| 8588056|116.TA.26-812-j19...| 20:07:00| 20:07:00| 9| 0| 0| 8588056| Uster, Talweg|47.3485132466833|8.73078014649001|\n", "| 8503872|166.TA.26-812-j19...| 12:18:00| 12:18:00| 4| 0| 0| 8503872| Uster, Reithalle|47.3562972036718|8.72678264347512|\n", "| 8588056|182.TA.26-812-j19...| 13:37:00| 13:37:00| 9| 0| 0| 8588056| Uster, Talweg|47.3485132466833|8.73078014649001|\n", "| 8573504|12.TA.26-813-j19-...| 17:57:00| 17:57:00| 8| 0| 0| 8573504| Uster, Bahnhof|47.3511851173852|8.71683829327853|\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": 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" }, { "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": 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" } ], "source": [ "calendar = spark.read.csv(\"/data/sbb/timetables/csv/calendar/2019/05/14/calendar.txt\", header=True, sep = \",\")" ] }, { "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": [ "+----------+------+-------+---------+--------+------+--------+------+----------+--------+\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": 20, "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": 21, "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": 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": [ "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": 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", "|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": 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" }, { "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": 25, "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+b0001| 1-1-C-j19-1|46.TA.1-1-C-j19-1...|Aarburg-Oftringen...| 113| 0|\n", "| TA+b0001| 1-1-C-j19-1|59.TA.1-1-C-j19-1...|Aarburg-Oftringen...| 139| 0|\n", "| TA+b0001| 1-340-j19-1|2.TA.1-340-j19-1.1.H| Wohlen AG, Bahnhof| 105| 0|\n", "| TA+b0001| 1-354-j19-1|36.TA.1-354-j19-1...|Kaiserstuhl AG, B...| 35435| 0|\n", "| TA+b0001| 1-354-j19-1|47.TA.1-354-j19-1...|Kaiserstuhl AG, B...| 35467| 0|\n", "| TA+b0001| 1-393-j19-1|70.TA.1-393-j19-1...|Othmarsingen, Bah...| 14060| 0|\n", "| TA+b0001| 1-508-j19-1|87.TA.1-508-j19-1...|Aarburg-Oftringen...| 8178| 1|\n", "| TA+b0001| 2-230-j19-1|28.TA.2-230-j19-1...| Trogen, Bahnhof| 23023| 0|\n", "| TA+b0001| 3-193-j19-1|221.TA.3-193-j19-...| Appenzell, Bahnhof| 1040| 1|\n", "| TA+b0001| 4-76-j19-1|54.TA.4-76-j19-1.2.H| Lausen, Furlen| 76049| 0|\n", "| TA+b0001| 6-101-j19-1|645.TA.6-101-j19-...| Beatenberg, Station| 10103| 0|\n", "| TA+b0001|6-11-A-j19-1|188.TA.6-11-A-j19...| Bern, Holligen| 11596| 1|\n", "| TA+b0001|6-11-B-j19-1|123.TA.6-11-B-j19...|Biel/Bienne, Bahn...| 11045| 1|\n", "| TA+b0001| 6-151-j19-1|54.TA.6-151-j19-1...| Brienz BE, Bahnhof| 236| 1|\n", "| TA+b0001| 6-21-j19-1|106.TA.6-21-j19-1...| Thun, Bahnhof| 21199| 1|\n", "| TA+b0001| 6-210-j19-1|23.TA.6-210-j19-1...| Frutigen, Bahnhof| 21025| 0|\n", "| TA+b0001| 6-27-j19-1|195.TA.6-27-j19-1...|Bern, Weyermannsh...| 17667| 1|\n", "| TA+b0001| 6-871-j19-1|43.TA.6-871-j19-1...| Waltwil| 71031| 0|\n", "| TA+b0001| 6-9-B-j19-1|28.TA.6-9-B-j19-1...| Bern| 9110| 1|\n", "| TA+b0001| 6-9-B-j19-1|43.TA.6-9-B-j19-1...| Bern| 9146| 1|\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": 26, "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": 27, "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", "| 1-1-C-j19-1|46.TA.1-1-C-j19-1...|Aarburg-Oftringen...| 113| 0|\n", "| 1-1-C-j19-1|59.TA.1-1-C-j19-1...|Aarburg-Oftringen...| 139| 0|\n", "| 1-340-j19-1|2.TA.1-340-j19-1.1.H| Wohlen AG, Bahnhof| 105| 0|\n", "| 1-354-j19-1|36.TA.1-354-j19-1...|Kaiserstuhl AG, B...| 35435| 0|\n", "| 1-354-j19-1|47.TA.1-354-j19-1...|Kaiserstuhl AG, B...| 35467| 0|\n", "| 1-393-j19-1|70.TA.1-393-j19-1...|Othmarsingen, Bah...| 14060| 0|\n", "| 1-508-j19-1|87.TA.1-508-j19-1...|Aarburg-Oftringen...| 8178| 1|\n", "| 2-230-j19-1|28.TA.2-230-j19-1...| Trogen, Bahnhof| 23023| 0|\n", "| 3-193-j19-1|221.TA.3-193-j19-...| Appenzell, Bahnhof| 1040| 1|\n", "| 4-76-j19-1|54.TA.4-76-j19-1.2.H| Lausen, Furlen| 76049| 0|\n", "| 6-101-j19-1|645.TA.6-101-j19-...| Beatenberg, Station| 10103| 0|\n", "|6-11-A-j19-1|188.TA.6-11-A-j19...| Bern, Holligen| 11596| 1|\n", "|6-11-B-j19-1|123.TA.6-11-B-j19...|Biel/Bienne, Bahn...| 11045| 1|\n", "| 6-151-j19-1|54.TA.6-151-j19-1...| Brienz BE, Bahnhof| 236| 1|\n", "| 6-21-j19-1|106.TA.6-21-j19-1...| Thun, Bahnhof| 21199| 1|\n", "| 6-210-j19-1|23.TA.6-210-j19-1...| Frutigen, Bahnhof| 21025| 0|\n", "| 6-27-j19-1|195.TA.6-27-j19-1...|Bern, Weyermannsh...| 17667| 1|\n", "| 6-871-j19-1|43.TA.6-871-j19-1...| Waltwil| 71031| 0|\n", "| 6-9-B-j19-1|28.TA.6-9-B-j19-1...| Bern| 9110| 1|\n", "| 6-9-B-j19-1|43.TA.6-9-B-j19-1...| Bern| 9146| 1|\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": 28, "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| stop_lat| stop_lon| route_id| trip_headsign|trip_short_name|direction_id|\n", "+--------------------+-----------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+----------------+----------------+------------+--------------------+---------------+------------+\n", "|1005.TA.26-131-j1...| 8589111| 16:15:00| 16:15:00| 2| 0| 0| 8589111|Horgen, Gumelenst...| 47.260856991692|8.59230484542371|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| 47.252107761586|8.60141376240595|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|47.2618568116556|8.59697608490178|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| 47.254772314364|8.59791931595024|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, ...|47.2586804890449|8.59024770342279|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|47.2615154118397|8.58892717995495|26-131-j19-1| Horgen, Aamüli| 636| 0|\n", "|1005.TA.26-131-j1...| 8573555| 16:19:00| 16:19:00| 5| 0| 0| 8573555| Horgen, Bergli|47.2576623184348| 8.5932121438608|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|47.2672701430669|8.65071330520529|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|47.2694401970586|8.64488323901054|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| 47.448965141581|8.58388763121034|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...| 47.453545361717|8.58019555539209|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,...|47.4524944976638|8.57205681891684|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,...|47.4506842895344|8.56372943623189|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|47.4509394233112|8.59648201149545|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...|47.4522454458795|8.58714851569215|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| 47.450745035784|8.58126455058034|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,...|47.4526524323306|8.56566081409302|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|47.4511884812805|8.59205331714412|26-733-j19-1| Kloten, Graswinkel| 4723| 1|\n", "|1087.TA.26-5-B-j1...| 8591058| 15:49:00| 15:49:00| 6| 0| 0| 8591058|Zürich Enge, Bahnhof|47.3641286895461|8.53156974905593|26-5-B-j19-1|Zürich, Kirche Fl...| 3194| 1|\n", "|1087.TA.26-5-B-j1...| 8591317| 15:51:00| 15:51:00| 7| 0| 0| 8591317|Zürich, Rentenans...|47.3633863608069|8.53503724605312|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": 29, "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": 30, "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| stop_lat| stop_lon| route_id| trip_headsign|trip_short_name|direction_id|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+----------------+----------------+-------------+--------------------+---------------+------------+\n", "|1.TA.26-925-j19-1...|8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof|47.2694401970586|8.64488323901054| 26-925-j19-1| Meilen, Bahnhof| 280| 0|\n", "|1.TA.26-925-j19-1...|8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen|47.2672701430669|8.65071330520529| 26-925-j19-1| Meilen, Bahnhof| 280| 0|\n", "|1014.TA.26-70-A-j...|8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|47.3444717091534|8.53296213774651|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...|47.3231389520848|8.51428616298707|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...|47.3414099167461|8.53031210765799|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|47.3303482449491|8.51537312448101|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...|47.3408255385719|8.52538035674749|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|47.3439482343686|8.53014142775399|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|47.3369660452942|8.52034979115572|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...|47.3264149182794|8.51466345540645|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...|47.3351336003511|8.51914604867483|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|47.3282354882425|8.51269614493396|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...|47.3470342259279| 8.5329172219823|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|1014.TA.26-70-A-j...|8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|47.3332523864039|8.51859807635144|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...|47.3476976601166|8.53331248070737|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0|\n", "|102.TA.26-765-j19...|8573211| 19:26:00| 19:26:00| 17| 0| 0| 8573211|Kloten, Zum Wilde...| 47.453545361717|8.58019555539209| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...|8503700| 19:12:00| 19:13:00| 7| 0| 0| 8503700|Bassersdorf, Bahnhof|47.4387159099396|8.62613539902836| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...|8590539| 19:03:00| 19:03:00| 1| 0| 0| 8590539|Dietlikon, Bahnho...|47.4219616816404|8.62080838939279| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...|8576153| 19:23:00| 19:23:00| 15| 0| 0| 8576153| Kloten, Rankstrasse|47.4511884812805|8.59205331714412| 26-765-j19-1|Zürich Flughafen,...| 1648| 1|\n", "|102.TA.26-765-j19...|8590503| 19:16:00| 19:16:00| 9| 0| 0| 8590503|Bassersdorf, Chlu...|47.4446275362315|8.62462622935083| 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": 31, "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": 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": [ "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+----------------+----------------+-------------+--------------------+---------------+------------+--------------+\n", "| trip_id|stop_id|arrival_time|departure_time|stop_sequence|pickup_type|drop_off_type|stop_id_general| stop_name| stop_lat| stop_lon| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+----------------+----------------+-------------+--------------------+---------------+------------+--------------+\n", "|1.TA.26-925-j19-1...|8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof|47.2694401970586|8.64488323901054| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1.TA.26-925-j19-1...|8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen|47.2672701430669|8.65071330520529| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1014.TA.26-70-A-j...|8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|47.3444717091534|8.53296213774651|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...|47.3231389520848|8.51428616298707|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|47.3414099167461|8.53031210765799|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|47.3303482449491|8.51537312448101|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|47.3408255385719|8.52538035674749|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|47.3439482343686|8.53014142775399|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|47.3369660452942|8.52034979115572|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...|47.3264149182794|8.51466345540645|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...|47.3351336003511|8.51914604867483|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|47.3282354882425|8.51269614493396|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...|47.3470342259279| 8.5329172219823|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|47.3332523864039|8.51859807635144|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|47.3476976601166|8.53331248070737|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|102.TA.26-765-j19...|8573211| 19:26:00| 19:26:00| 17| 0| 0| 8573211|Kloten, Zum Wilde...| 47.453545361717|8.58019555539209| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8503700| 19:12:00| 19:13:00| 7| 0| 0| 8503700|Bassersdorf, Bahnhof|47.4387159099396|8.62613539902836| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8590539| 19:03:00| 19:03:00| 1| 0| 0| 8590539|Dietlikon, Bahnho...|47.4219616816404|8.62080838939279| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8576153| 19:23:00| 19:23:00| 15| 0| 0| 8576153| Kloten, Rankstrasse|47.4511884812805|8.59205331714412| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8590503| 19:16:00| 19:16:00| 9| 0| 0| 8590503|Bassersdorf, Chlu...|47.4446275362315|8.62462622935083| 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": 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| stop_lat| stop_lon| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+----------------+----------------+-------------+--------------------+---------------+------------+--------------+\n", "|1.TA.26-925-j19-1...|8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof|47.2694401970586|8.64488323901054| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1.TA.26-925-j19-1...|8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen|47.2672701430669|8.65071330520529| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1014.TA.26-70-A-j...|8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|47.3444717091534|8.53296213774651|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...|47.3231389520848|8.51428616298707|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|47.3414099167461|8.53031210765799|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|47.3303482449491|8.51537312448101|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|47.3408255385719|8.52538035674749|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|47.3439482343686|8.53014142775399|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|47.3369660452942|8.52034979115572|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...|47.3264149182794|8.51466345540645|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...|47.3351336003511|8.51914604867483|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|47.3282354882425|8.51269614493396|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...|47.3470342259279| 8.5329172219823|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|47.3332523864039|8.51859807635144|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|47.3476976601166|8.53331248070737|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|102.TA.26-765-j19...|8573211| 19:26:00| 19:26:00| 17| 0| 0| 8573211|Kloten, Zum Wilde...| 47.453545361717|8.58019555539209| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8503700| 19:12:00| 19:13:00| 7| 0| 0| 8503700|Bassersdorf, Bahnhof|47.4387159099396|8.62613539902836| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8590539| 19:03:00| 19:03:00| 1| 0| 0| 8590539|Dietlikon, Bahnho...|47.4219616816404|8.62080838939279| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8576153| 19:23:00| 19:23:00| 15| 0| 0| 8576153| Kloten, Rankstrasse|47.4511884812805|8.59205331714412| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8590503| 19:16:00| 19:16:00| 9| 0| 0| 8590503|Bassersdorf, Chlu...|47.4446275362315|8.62462622935083| 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": 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" } ], "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": 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" }, { "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": 36, "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| stop_lat| stop_lon| route_id| trip_headsign|trip_short_name|direction_id|departure_hour|\n", "+--------------------+-------+------------+--------------+-------------+-----------+-------------+---------------+--------------------+----------------+----------------+-------------+--------------------+---------------+------------+--------------+\n", "|1.TA.26-925-j19-1...|8576080| 15:27:00| 15:27:00| 23| 0| 0| 8576080| Meilen, Bahnhof|47.2694401970586|8.64488323901054| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1.TA.26-925-j19-1...|8576082| 15:22:00| 15:22:00| 22| 0| 0| 8576082| Meilen, Beugen|47.2672701430669|8.65071330520529| 26-925-j19-1| Meilen, Bahnhof| 280| 0| 15|\n", "|1014.TA.26-70-A-j...|8591304| 11:54:00| 11:54:00| 3| 0| 0| 8591304|Zürich, Post Woll...|47.3444717091534|8.53296213774651|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...|47.3231389520848|8.51428616298707|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8591106| 11:56:00| 11:56:00| 5| 0| 0| 8591106|Zürich, Butzenstr...|47.3414099167461|8.53031210765799|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|47.3303482449491|8.51537312448101|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8591410| 11:57:00| 11:57:00| 6| 0| 0| 8591410|Zürich, Verenastr...|47.3408255385719|8.52538035674749|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591279| 11:55:00| 11:55:00| 4| 0| 0| 8591279| Zürich, Morgental|47.3439482343686|8.53014142775399|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591268| 11:58:00| 11:58:00| 7| 0| 0| 8591268| Zürich, Manegg|47.3369660452942|8.52034979115572|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...|47.3264149182794|8.51466345540645|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...|47.3351336003511|8.51914604867483|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|47.3282354882425|8.51269614493396|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...|47.3470342259279| 8.5329172219823|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|1014.TA.26-70-A-j...|8591061| 12:00:00| 12:01:00| 9| 0| 0| 8591061|Zürich Leimbach, ...|47.3332523864039|8.51859807635144|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 12|\n", "|1014.TA.26-70-A-j...|8502495| 11:51:00| 11:51:00| 1| 0| 0| 8502495|Zürich Wollishofe...|47.3476976601166|8.53331248070737|26-70-A-j19-1|Zürich, Mittellei...| 3400| 0| 11|\n", "|102.TA.26-765-j19...|8573211| 19:26:00| 19:26:00| 17| 0| 0| 8573211|Kloten, Zum Wilde...| 47.453545361717|8.58019555539209| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8503700| 19:12:00| 19:13:00| 7| 0| 0| 8503700|Bassersdorf, Bahnhof|47.4387159099396|8.62613539902836| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8590539| 19:03:00| 19:03:00| 1| 0| 0| 8590539|Dietlikon, Bahnho...|47.4219616816404|8.62080838939279| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8576153| 19:23:00| 19:23:00| 15| 0| 0| 8576153| Kloten, Rankstrasse|47.4511884812805|8.59205331714412| 26-765-j19-1|Zürich Flughafen,...| 1648| 1| 19|\n", "|102.TA.26-765-j19...|8590503| 19:16:00| 19:16:00| 9| 0| 0| 8590503|Bassersdorf, Chlu...|47.4446275362315|8.62462622935083| 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": 37, "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| stop_lat| stop_lon| 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...|47.3516902622456|8.34617544069354|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...|47.3475576701104|8.34819665008309|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| 47.34464822855| 8.3519875405826|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|47.3417386266265|8.35463757067112|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...|47.3221585583935| 8.380473118246|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...|47.3133646488037| 8.3889172819179|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|47.3133829202162|8.38868371994399|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...|47.3123840737352|8.39276207133446|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...|47.3134255534873|8.39881671635027|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|47.3183951391194| 8.4197115298618|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|47.3200332946963|8.42388869593354|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|47.3183951391194| 8.4197115298618|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...|47.3134255534873|8.39881671635027|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...|47.3123840737352|8.39276207133446|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...|47.3113973897738|8.39072289563923|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|47.3019681473342|8.39299563330837|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|47.2994704564101|8.39385801598124|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|47.2961806346557|8.39551091610425|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|47.4200714067302| 8.3754784852656| 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...|47.4188375250837|8.36858840703544| 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": 38, "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": 39, "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": 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 |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": 41, "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": 42, "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", "|366.TA.11-3-j19-1...|[8503000]| [15:23:00]| [15:23:00]| 1|\n", "|457.TA.26-24-j19-...|[8502208]| [16:45:00]| [16:45:00]| 1|\n", "|99.TA.1-321-j19-1...|[8502750]| [16:07:00]| [16:07:00]| 1|\n", "|31.TA.80-158-Y-j1...|[8503000]| [14:38:00]| [14:38:00]| 1|\n", "|423.TA.1-36-j19-1...|[8503000]| [09:36:00]| [09:36:00]| 1|\n", "|808.TA.26-24-j19-...|[8502208]| [17:15:00]| [17:15:00]| 1|\n", "|1.TA.20-E03-j19-1...|[8596126]| [19:15:00]| [19:10:00]| 1|\n", "|103.TA.1-321-j19-...|[8502750]| [18:07:00]| [18:07:00]| 1|\n", "|123.TA.1-321-j19-...|[8502750]| [12:07:00]| [12:07:00]| 1|\n", "|141.TA.20-2-j19-1...|[8503000]| [08:10:00]| [08:10:00]| 1|\n", "|17.TA.17-4-j19-1.5.H|[8503000]| [12:37:00]| [12:37:00]| 1|\n", "|17.TA.80-158-Y-j1...|[8503000]| [10:38:00]| [10:38:00]| 1|\n", "|346.TA.1-37-j19-1...|[8503000]| [11:08:00]| [11:08:00]| 1|\n", "|399.TA.11-3-j19-1...|[8503000]| [11:37:00]| [11:37:00]| 1|\n", "| 4.TA.17-4-j19-1.4.H|[8503000]| [18:37:00]| [18:37:00]| 1|\n", "|450.TA.1-16-j19-1...|[8503000]| [15:54:00]| [15:54:00]| 1|\n", "|611.TA.26-8-A-j19...|[8503204]| [07:00:00]| [06:59:00]| 1|\n", "|178.TA.20-2-j19-1...|[8503000]| [19:18:00]| [19:18:00]| 1|\n", "|410.TA.26-24-j19-...|[8502208]| [10:45:00]| [10:45:00]| 1|\n", "|1.TA.57-2-Y-j19-1...|[8503000]| [09:34:00]| [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": 43, "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": 44, "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": 45, "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": 46, "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": 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" } ], "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": 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" } ], "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": 49, "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", "|279.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": 50, "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": 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|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", "|80.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", "|281.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", "|982.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": 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": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+\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": 53, "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", "|[8591049, 8591128...|\n", "|[8591057, 8591402...|\n", "| [8591281, 8591046]|\n", "|[8591825, 8590504...|\n", "| [8573205, 8588553]|\n", "|[8576240, 8591353...|\n", "|[8591061, 8591270...|\n", "|[8575921, 8575920...|\n", "|[8591035, 8591134...|\n", "|[8595129, 8590543...|\n", "|[8576127, 8576139...|\n", "|[8503010, 8503011...|\n", "| [8575927, 8594339]|\n", "|[8591031, 8588553...|\n", "|[8503674, 8503659...|\n", "|[8576171, 8576172...|\n", "|[8576276, 8576277...|\n", "|[8590805, 8590794...|\n", "|[8591110, 8591306...|\n", "|[8502208, 8502209...|\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": 54, "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": 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", "|route_int| all_stops|\n", "+---------+--------------------+\n", "| 0|[8576240, 8591353...|\n", "| 1|[8591049, 8591128...|\n", "| 2|[8591057, 8591402...|\n", "| 3| [8591281, 8591046]|\n", "| 4|[8591825, 8590504...|\n", "| 5| [8573205, 8588553]|\n", "| 6|[8591061, 8591270...|\n", "| 7|[8575921, 8575920...|\n", "| 8|[8595129, 8590543...|\n", "| 9|[8591035, 8591134...|\n", "| 10|[8503010, 8503011...|\n", "| 11|[8591031, 8588553...|\n", "| 12| [8575927, 8594339]|\n", "| 13|[8576127, 8576139...|\n", "| 14|[8502208, 8502209...|\n", "| 15|[8503674, 8503659...|\n", "| 16|[8576171, 8576172...|\n", "| 17|[8590805, 8590794...|\n", "| 18|[8591110, 8591306...|\n", "| 19|[8576276, 8576277...|\n", "+---------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "routes_indexed = dfZipWithIndex(routes, 0, 'route_int')\n", "routes_indexed.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": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "| all_stops| trip_id| all_departures| all_arrivals|stop_count|departure_first_stop|route_int|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "|[8591825, 8590504...|117.TA.26-703-j19...|[18:04:00, 18:05:...|[18:04:00, 18:05:...| 9| 18:04:00| 4|\n", "|[8591355, 8591354...|1232.TA.26-75-A-j...|[17:06:00, 17:07:...|[17:06:00, 17:07:...| 21| 17:06:00| 78|\n", "|[8591355, 8591354...|1135.TA.26-75-A-j...|[12:59:00, 13:00:...|[12:59:00, 13:00:...| 21| 12:59:00| 78|\n", "|[8591401, 8503610...|1269.TA.26-80-j19...|[19:22:00, 19:23:...|[19:22:00, 19:23:...| 29| 19:22:00| 108|\n", "|[8580449, 8591063...|1892.TA.26-781-j1...|[15:17:00, 15:18:...|[15:17:00, 15:18:...| 12| 15:17:00| 136|\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", "|[8590716, 8590714...|364.TA.26-743-j19...|[15:30:00, 15:30:...|[15:30:00, 15:30:...| 17| 15:30:00| 278|\n", "|[8590804, 8590805...|730.TA.26-31-j19-...|[12:32:00, 12:33:...|[12:32:00, 12:33:...| 9| 12:32:00| 281|\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", "|[8591439, 8591106...|1316.TA.26-7-B-j1...|[18:20:00, 18:21:...|[18:20:00, 18:21:...| 31| 18:20:00| 321|\n", "|[8503104, 8503101...|6.TA.26-20-j19-1.2.H|[07:46:00, 07:53:...|[07:45:00, 07:52:...| 5| 07:46:00| 375|\n", "|[8591136, 8591435...|2056.TA.26-13-j19...|[19:47:00, 19:48:...|[19:47:00, 19:48:...| 10| 19:47:00| 396|\n", "|[8591122, 8591201...|1133.TA.26-69-j19...|[17:37:00, 17:38:...|[17:37:00, 17:38:...| 9| 17:37:00| 400|\n", "|[8503059, 8530813...|427.TA.26-18-j19-...|[14:33:00, 14:34:...|[14:33:00, 14:34:...| 13| 14:33:00| 432|\n", "|[8590637, 8590636...|92.TA.26-727-j19-...|[14:17:00, 14:18:...|[14:17:00, 14:18:...| 9| 14:17:00| 434|\n", "|[8590901, 8590903...|637.TA.26-759-j19...|[09:08:00, 09:09:...|[09:08:00, 09:09:...| 28| 09:08:00| 460|\n", "|[8591190, 8591390...|285.TA.26-9-B-j19...|[09:54:00, 09:55:...|[09:54:00, 09:55:...| 32| 09:54:00| 551|\n", "|[8591354, 8591124...|673.TA.26-768-j19...|[07:00:00, 07:02:...|[07:00:00, 07:02:...| 9| 07:00:00| 586|\n", "|[8591057, 8591896...|1201.TA.26-4-j19-...|[12:31:00, 12:32:...|[12:31:00, 12:32:...| 26| 12:31:00| 608|\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": 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": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "| all_stops| trip_id| all_departures| all_arrivals|stop_count|departure_first_stop|route_int|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "|8591825 8590504 8...|117.TA.26-703-j19...|18:04:00 18:05:00...|18:04:00 18:05:00...| 9| 18:04:00| 4|\n", "|8591355 8591354 8...|1232.TA.26-75-A-j...|17:06:00 17:07:00...|17:06:00 17:07:00...| 21| 17:06:00| 78|\n", "|8591355 8591354 8...|1135.TA.26-75-A-j...|12:59:00 13:00:00...|12:59:00 13:00:00...| 21| 12:59:00| 78|\n", "|8591276 8591101 8...|570.TA.26-69-j19-...|15:21:00 15:23:00...|15:21:00 15:23:00...| 9| 15:21:00| 104|\n", "|8573504 8581548 8...|247.TA.26-813-j19...|19:15:00 19:15:00...|19:15:00 19:15:00...| 8| 19:15:00| 112|\n", "|8590785 8590722 8...|14.TA.79-18-A-j19...|11:41:00 11:43:00...|11:41:00 11:43:00...| 5| 11:41:00| 117|\n", "|8580449 8591063 8...|1892.TA.26-781-j1...|15:17:00 15:18:00...|15:17:00 15:18:00...| 12| 15:17:00| 136|\n", "|8503016 8503006 8...|496.TA.26-24-j19-...|07:04:00 07:09:00...|07:02:00 07:08:00...| 12| 07:04:00| 198|\n", "|8591067 8587349 8...|1673.TA.26-17-j19...|15:11:00 15:13:00...|15:11:00 15:13:00...| 17| 15:11:00| 218|\n", "|8580433 8580438 8...|170.TA.26-733-j19...|18:30:00 18:31:00...|18:30:00 18:31:00...| 10| 18:30:00| 239|\n", "|8591116 8591260 8...|190.TA.26-35-B-j1...|19:27:00 19:28:00...|19:27:00 19:28:00...| 8| 19:27:00| 290|\n", "|8591439 8591106 8...|1316.TA.26-7-B-j1...|18:20:00 18:21:00...|18:20:00 18:21:00...| 31| 18:20:00| 321|\n", "|8591136 8591435 8...|2056.TA.26-13-j19...|19:47:00 19:48:00...|19:47:00 19:48:00...| 10| 19:47:00| 396|\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", "|8590637 8590636 8...|92.TA.26-727-j19-...|14:17:00 14:18:00...|14:17:00 14:18:00...| 9| 14:17:00| 434|\n", "|8590318 8591051 8...|436.TA.26-2-A-j19...|09:58:00 09:59:00...|09:58:00 09:59:00...| 25| 09:58:00| 578|\n", "|8591341 8502572 8...|605.TA.26-67-j19-...|17:21:00 17:22:00...|17:21:00 17:22:00...| 14| 17:21:00| 579|\n", "|8591341 8502572 8...|43.TA.26-67-j19-1...|09:50:00 09:52:00...|09:50:00 09:52:00...| 14| 09:50:00| 579|\n", "|8591341 8502572 8...|75.TA.26-67-j19-1...|09:28:00 09:29:00...|09:28:00 09:29:00...| 14| 09:28:00| 579|\n", "|8591057 8591896 8...|1201.TA.26-4-j19-...|12:31:00 12:32:00...|12:31:00 12:32:00...| 26| 12:31:00| 608|\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": 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_string_lists.write.csv('data/lgpt_guys/trips_unique_string_lists.csv', header = True, mode=\"overwrite\")" ] }, { "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" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "| all_stops| trip_id| all_departures| all_arrivals|stop_count|departure_first_stop|route_int|\n", "+--------------------+--------------------+--------------------+--------------------+----------+--------------------+---------+\n", "|8590464 8590463 8...|603.TA.26-185-j19...|17:51:00 17:53:00...|17:51:00 17:53:00...| 14| 17:51:00| 21|\n", "|8503305 8503306 8...|641.TA.26-8-A-j19...|09:19:00 09:23:00...|09:18:00 09:23:00...| 13| 09:19:00| 43|\n", "|8503057 8503056 8...|139.TA.26-10-B-j1...|13:54:00 13:59:00...|13:54:00 13:59:00...| 8| 13:54:00| 83|\n", "|8591401 8503610 8...|1310.TA.26-80-j19...|17:51:00 17:52:00...|17:51:00 17:52:00...| 29| 17:51:00| 108|\n", "|8591401 8503610 8...|1341.TA.26-80-j19...|16:51:00 16:52:00...|16:51:00 16:52:00...| 29| 16:51:00| 108|\n", "|8503097 8503089 8...|19.TA.26-4-B-j19-...|11:10:00 11:11:00...|11:10:00 11:11:00...| 12| 11:10:00| 129|\n", "|8590269 8590276 8...|280.TA.26-303-j19...|07:51:00 07:52:00...|07:51:00 07:52:00...| 23| 07:51:00| 144|\n", "|8591065 8590566 8...|126.TA.26-751-j19...|15:59:00 15:59:00...|15:59:00 15:59:00...| 10| 15:59:00| 146|\n", "|8591349 8591403 8...|421.TA.26-61-j19-...|08:42:00 08:43:00...|08:42:00 08:43:00...| 19| 08:42:00| 148|\n", "|8591067 8587349 8...|1514.TA.26-17-j19...|14:11:00 14:13:00...|14:11:00 14:13:00...| 17| 14:11:00| 221|\n", "|8591067 8587349 8...|1546.TA.26-17-j19...|12:33:00 12:36:00...|12:33:00 12:36:00...| 17| 12:33:00| 221|\n", "|8580433 8580438 8...|195.TA.26-733-j19...|14:45:00 14:46:00...|14:45:00 14:46:00...| 10| 14:45:00| 238|\n", "|8580433 8580438 8...|247.TA.26-733-j19...|07:15:00 07:16:00...|07:15:00 07:16:00...| 10| 07:15:00| 238|\n", "|8590647 8587998 8...|42.TA.26-973-j19-...|15:08:00 15:09:00...|15:08:00 15:09:00...| 14| 15:08:00| 274|\n", "|8591054 8576262 8...|113.TA.26-37-A-j1...|08:48:00 08:50:00...|08:48:00 08:50:00...| 6| 08:48:00| 275|\n", "|8580449 8591063 8...|1101.TA.26-768-j1...|16:08:00 16:09:00...|16:08:00 16:09:00...| 13| 16:08:00| 297|\n", "|8591439 8591106 8...|1320.TA.26-7-B-j1...|17:50:00 17:51:00...|17:50:00 17:51:00...| 31| 17:50:00| 320|\n", "|8591439 8591106 8...|1338.TA.26-7-B-j1...|08:30:00 08:31:00...|08:30:00 08:31:00...| 31| 08:30:00| 320|\n", "|8573504 8588051 8...|10.TA.26-812-j19-...|16:45:00 16:45:00...|16:45:00 16:45:00...| 12| 16:45:00| 331|\n", "|8591230 8591087 8...|197.TA.26-751-j19...|16:35:00 16:36:00...|16:35:00 16:36:00...| 9| 16:35:00| 405|\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": 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|departure_first_stop|route_int|stop_count|\n", "+--------------------+--------------------+---------+----------+\n", "|603.TA.26-185-j19...| 17:51:00| 21| 14|\n", "|641.TA.26-8-A-j19...| 09:19:00| 43| 13|\n", "|139.TA.26-10-B-j1...| 13:54:00| 83| 8|\n", "|1310.TA.26-80-j19...| 17:51:00| 108| 29|\n", "|1341.TA.26-80-j19...| 16:51:00| 108| 29|\n", "|19.TA.26-4-B-j19-...| 11:10:00| 129| 12|\n", "|280.TA.26-303-j19...| 07:51:00| 144| 23|\n", "|126.TA.26-751-j19...| 15:59:00| 146| 10|\n", "|421.TA.26-61-j19-...| 08:42:00| 148| 19|\n", "|1514.TA.26-17-j19...| 14:11:00| 221| 17|\n", "|1546.TA.26-17-j19...| 12:33:00| 221| 17|\n", "|195.TA.26-733-j19...| 14:45:00| 238| 10|\n", "|247.TA.26-733-j19...| 07:15:00| 238| 10|\n", "|42.TA.26-973-j19-...| 15:08:00| 274| 14|\n", "|113.TA.26-37-A-j1...| 08:48:00| 275| 6|\n", "|1101.TA.26-768-j1...| 16:08:00| 297| 13|\n", "|1320.TA.26-7-B-j1...| 17:50:00| 320| 31|\n", "|1338.TA.26-7-B-j1...| 08:30:00| 320| 31|\n", "|10.TA.26-812-j19-...| 16:45:00| 331| 12|\n", "|197.TA.26-751-j19...| 16:35:00| 405| 9|\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": 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": [ "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": [ "Note that this csv is does not carry an index allowing to quickly sort it after loading." ] }, { "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" } ], "source": [ "stop_times.write.csv('data/lgpt_guys/stop_times_with_route_int.csv', header=True, mode='overwrite')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 7 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": 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" } ], "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": 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": [ "1461" ] } ], "source": [ "stop_times.select(stop_times.route_int).dropDuplicates().count()" ] }, { "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" }, { "name": "stdout", "output_type": "stream", "text": [ "+--------+---------------+\n", "|stop_int|stop_id_general|\n", "+--------+---------------+\n", "| 0| 8503376|\n", "| 1| 8502508|\n", "| 2| 8503088|\n", "| 3| 8589111|\n", "| 4| 8591284|\n", "| 5| 8591190|\n", "| 6| 8503078|\n", "| 7| 8587967|\n", "| 8| 8590819|\n", "| 9| 8591362|\n", "| 10| 8591149|\n", "| 11| 8591315|\n", "| 12| 8588312|\n", "| 13| 8590541|\n", "| 14| 8590804|\n", "| 15| 8591085|\n", "| 16| 8590273|\n", "| 17| 8591271|\n", "| 18| 8591165|\n", "| 19| 8591080|\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": 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" } ], "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": 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" } ], "source": [ "stops_general_indexed = spark.read.csv('data/lgpt_guys/stops_general_indexed.csv', header=True)" ] }, { "cell_type": "code", "execution_count": 68, "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| stop_lat| stop_lon| route_id| trip_headsign|trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|\n", "+---------------+--------------------+-------+------------+--------------+-------------+--------------------+----------------+----------------+------------+--------------------+---------------+------------+--------------------+---------+----------+--------+\n", "| 8590679|610.TA.26-185-j19...|8590679| 10:56:00| 10:56:00| 5|Kilchberg ZH, Spital|47.3217079365566|8.53537860586113|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 65|\n", "| 8590468|610.TA.26-185-j19...|8590468| 10:58:00| 10:58:00| 6| Adliswil, Eichenweg|47.3200028461711|8.53368977312675|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1171|\n", "| 8590477|610.TA.26-185-j19...|8590477| 10:59:00| 10:59:00| 7| Adliswil, Moos|47.3254528526241|8.53104872619107|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 15|\n", "| 8591388|610.TA.26-185-j19...|8591388| 11:00:00| 11:00:00| 8| Zürich, Sunnau|47.3270847004784|8.52961142173628|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1234|\n", "| 8591111|610.TA.26-185-j19...|8591111| 11:02:00| 11:02:00| 9|Zürich, Dangelstr...|47.3345491527085|8.52997973100282|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 433|\n", "| 8591439|610.TA.26-185-j19...|8591439| 11:03:00| 11:03:00| 10| Zürich, Wollishofen|47.3384392605619|8.53015939405967|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 552|\n", "| 8591106|610.TA.26-185-j19...|8591106| 11:03:00| 11:03:00| 11|Zürich, Butzenstr...|47.3414099167461|8.53031210765799|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1037|\n", "| 8591279|610.TA.26-185-j19...|8591279| 11:05:00| 11:05:00| 12| Zürich, Morgental|47.3439482343686|8.53014142775399|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1349|\n", "| 8591304|610.TA.26-185-j19...|8591304| 11:06:00| 11:06:00| 13|Zürich, Post Woll...|47.3444717091534|8.53296213774651|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 982|\n", "| 8502495|610.TA.26-185-j19...|8502495| 11:07:00| 11:07:00| 14|Zürich Wollishofe...|47.3476976601166|8.53331248070737|26-185-j19-1|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 116|\n", "| 8591036|610.TA.26-3-A-j19...|8591036| 08:18:00| 08:18:00| 1| Zürich, Albisrieden|47.3743863596743|8.48478548905248|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 1356|\n", "| 8591126|610.TA.26-3-A-j19...|8591126| 08:20:00| 08:20:00| 2|Zürich, Fellenber...|47.3757186152716|8.48841468280083|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 744|\n", "| 8591363|610.TA.26-3-A-j19...|8591363| 08:21:00| 08:21:00| 3| Zürich, Siemens|47.3785837632719|8.49449627727516|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 264|\n", "| 8591203|610.TA.26-3-A-j19...|8591203| 08:23:00| 08:23:00| 4| Zürich, Hubertus|47.3768744261929|8.49947294394988|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 569|\n", "| 8591236|610.TA.26-3-A-j19...|8591236| 08:24:00| 08:24:00| 5|Zürich, Krematori...|47.3778051397306|8.50787219185756|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 368|\n", "| 8591038|610.TA.26-3-A-j19...|8591038| 08:25:00| 08:25:00| 6|Zürich, Albisried...|47.3782127019246|8.51039645780629|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 1190|\n", "| 8591448|610.TA.26-3-A-j19...|8591448| 08:26:00| 08:26:00| 7|Zürich, Zypressen...|47.3766919314159|8.51376514012221|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 773|\n", "| 8591259|610.TA.26-3-A-j19...|8591259| 08:28:00| 08:28:00| 8| Zürich, Lochergut|47.3753475337612|8.51791535673542|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 653|\n", "| 8591218|610.TA.26-3-A-j19...|8591218| 08:29:00| 08:29:00| 9|Zürich,Kalkbreite...|47.3745992794953|8.52100556131322|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 247|\n", "| 8591079|610.TA.26-3-A-j19...|8591079| 08:30:00| 08:30:00| 10|Zürich, Bezirksge...|47.3741673555329|8.52556001980434|26-3-A-j19-1| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 1062|\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": [ "# 8 Adding transport types to stop_times from routes.txt" ] }, { "cell_type": "code", "execution_count": 69, "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": 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", "| 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": 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" }, { "name": "stdout", "output_type": "stream", "text": [ "+------------+---------------+--------------------+-------+------------+--------------+-------------+--------------------+----------------+----------------+--------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "| route_id|stop_id_general| trip_id|stop_id|arrival_time|departure_time|stop_sequence| stop_name| stop_lat| stop_lon| trip_headsign|trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|\n", "+------------+---------------+--------------------+-------+------------+--------------+-------------+--------------------+----------------+----------------+--------------------+---------------+------------+--------------------+---------+----------+--------+----------+\n", "|26-185-j19-1| 8590679|610.TA.26-185-j19...|8590679| 10:56:00| 10:56:00| 5|Kilchberg ZH, Spital|47.3217079365566|8.53537860586113|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 65| Bus|\n", "|26-185-j19-1| 8590468|610.TA.26-185-j19...|8590468| 10:58:00| 10:58:00| 6| Adliswil, Eichenweg|47.3200028461711|8.53368977312675|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1171| Bus|\n", "|26-185-j19-1| 8590477|610.TA.26-185-j19...|8590477| 10:59:00| 10:59:00| 7| Adliswil, Moos|47.3254528526241|8.53104872619107|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 15| Bus|\n", "|26-185-j19-1| 8591388|610.TA.26-185-j19...|8591388| 11:00:00| 11:00:00| 8| Zürich, Sunnau|47.3270847004784|8.52961142173628|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1234| Bus|\n", "|26-185-j19-1| 8591111|610.TA.26-185-j19...|8591111| 11:02:00| 11:02:00| 9|Zürich, Dangelstr...|47.3345491527085|8.52997973100282|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 433| Bus|\n", "|26-185-j19-1| 8591439|610.TA.26-185-j19...|8591439| 11:03:00| 11:03:00| 10| Zürich, Wollishofen|47.3384392605619|8.53015939405967|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 552| Bus|\n", "|26-185-j19-1| 8591106|610.TA.26-185-j19...|8591106| 11:03:00| 11:03:00| 11|Zürich, Butzenstr...|47.3414099167461|8.53031210765799|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1037| Bus|\n", "|26-185-j19-1| 8591279|610.TA.26-185-j19...|8591279| 11:05:00| 11:05:00| 12| Zürich, Morgental|47.3439482343686|8.53014142775399|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 1349| Bus|\n", "|26-185-j19-1| 8591304|610.TA.26-185-j19...|8591304| 11:06:00| 11:06:00| 13|Zürich, Post Woll...|47.3444717091534|8.53296213774651|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 982| Bus|\n", "|26-185-j19-1| 8502495|610.TA.26-185-j19...|8502495| 11:07:00| 11:07:00| 14|Zürich Wollishofe...|47.3476976601166|8.53331248070737|Zürich Wollishofe...| 9270| 1| 10:51:00| 21| 14| 116| Bus|\n", "|26-3-A-j19-1| 8591036|610.TA.26-3-A-j19...|8591036| 08:18:00| 08:18:00| 1| Zürich, Albisrieden|47.3743863596743|8.48478548905248| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 1356| Tram|\n", "|26-3-A-j19-1| 8591126|610.TA.26-3-A-j19...|8591126| 08:20:00| 08:20:00| 2|Zürich, Fellenber...|47.3757186152716|8.48841468280083| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 744| Tram|\n", "|26-3-A-j19-1| 8591363|610.TA.26-3-A-j19...|8591363| 08:21:00| 08:21:00| 3| Zürich, Siemens|47.3785837632719|8.49449627727516| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 264| Tram|\n", "|26-3-A-j19-1| 8591203|610.TA.26-3-A-j19...|8591203| 08:23:00| 08:23:00| 4| Zürich, Hubertus|47.3768744261929|8.49947294394988| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 569| Tram|\n", "|26-3-A-j19-1| 8591236|610.TA.26-3-A-j19...|8591236| 08:24:00| 08:24:00| 5|Zürich, Krematori...|47.3778051397306|8.50787219185756| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 368| Tram|\n", "|26-3-A-j19-1| 8591038|610.TA.26-3-A-j19...|8591038| 08:25:00| 08:25:00| 6|Zürich, Albisried...|47.3782127019246|8.51039645780629| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 1190| Tram|\n", "|26-3-A-j19-1| 8591448|610.TA.26-3-A-j19...|8591448| 08:26:00| 08:26:00| 7|Zürich, Zypressen...|47.3766919314159|8.51376514012221| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 773| Tram|\n", "|26-3-A-j19-1| 8591259|610.TA.26-3-A-j19...|8591259| 08:28:00| 08:28:00| 8| Zürich, Lochergut|47.3753475337612|8.51791535673542| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 653| Tram|\n", "|26-3-A-j19-1| 8591218|610.TA.26-3-A-j19...|8591218| 08:29:00| 08:29:00| 9|Zürich,Kalkbreite...|47.3745992794953|8.52100556131322| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 247| Tram|\n", "|26-3-A-j19-1| 8591079|610.TA.26-3-A-j19...|8591079| 08:30:00| 08:30:00| 10|Zürich, Bezirksge...|47.3741673555329|8.52556001980434| Zürich, Klusplatz| 1059| 0| 08:18:00| 1282| 21| 1062| Tram|\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": [ "## 9 VERY IMPORTANT: final sort before writing to csv" ] }, { "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", "|route_id |stop_id_general|trip_id |stop_id|arrival_time|departure_time|stop_sequence|stop_name |stop_lat |stop_lon |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|monotonically_increasing_id|\n", "+-------------+---------------+------------------------+-------+------------+--------------+-------------+------------------------------+----------------+----------------+---------------------------+---------------+------------+--------------------+---------+----------+--------+----------+---------------------------+\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 |47.4020100860391|8.49937412926861|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1221 |Tram |0 |\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 |47.3997299435837|8.50461130737576|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |816 |Tram |1 |\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 |47.3977659017765|8.50725235431143|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |776 |Tram |2 |\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 |47.3962700189648|8.51204037477646|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |307 |Tram |3 |\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 |47.3954977376399|8.51840044698891|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |347 |Tram |4 |\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 |47.3925909395293|8.52357474302616|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1015 |Tram |5 |\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 |47.3907969150758|8.5223979500038 |Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |455 |Tram |6 |\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 |47.3884919601296|8.52639545301869|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1102 |Tram |7 |\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 |47.3867403702341|8.52874903906341|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |786 |Tram |8 |\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 |47.3845994590919|8.53162364797299|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |388 |Tram |9 |\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 |47.3821239221899|8.53493843137185|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |138 |Tram |10 |\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 |47.3798733332196|8.53760642776606|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |880 |Tram |11 |\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 |47.3775618175159|8.54173867807358|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |602 |Tram |12 |\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 |47.3765581015114|8.53994204750509|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |616 |Tram |13 |\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 |47.3730662375955|8.53845982728609|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |373 |Tram |14 |\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 |47.3693672863583|8.53876525448273|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1223 |Tram |15 |\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 |47.3677002399791|8.53501029659459|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |871 |Tram |16 |\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 |47.3661426599847|8.53253094641008|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |890 |Tram |17 |\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.|47.3645546111557|8.53045583810347|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |177 |Tram |18 |\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 |47.3614818138862|8.52574866601403|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1265 |Tram |19 |\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 |47.3600640074787|8.52303575385561|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |968 |Tram |20 |\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 |47.3578611597087|8.52040369007277|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1238 |Tram |21 |\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 |47.3587313564196|8.51708890667391|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1216 |Tram |22 |\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 |47.3567353594536|8.51396276948474|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |847 |Tram |23 |\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 |47.3530717783138|8.51171698127413|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |275 |Tram |24 |\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 |47.3519945640447|8.5077104951064 |Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1352 |Tram |25 |\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 |47.4166918393693|8.568113214819 |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |1117 |Tram |26 |\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 |47.4181749855684|8.56174415945371|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |156 |Tram |27 |\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 |47.4199559214972|8.55716275150406|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |671 |Tram |28 |\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 |47.4175853791724|8.5542072942189 |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |573 |Tram |29 |\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 |47.4146433269471|8.55130573585079|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |444 |Tram |30 |\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 |47.4106919651348|8.55068589830466|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |389 |Tram |31 |\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 |47.4100718783688|8.54623025449481|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |687 |Tram |32 |\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 |47.411494419524 |8.54479295004002|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |766 |Tram |33 |\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 |47.392067942097 |8.48990588617267|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |521 |Bus |34 |\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 |47.3979787271809|8.49434356367684|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1000 |Bus |35 |\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 |47.4000582901792|8.4945681424979 |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |711 |Bus |36 |\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 |47.4013473348052|8.49021131336931|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1125 |Bus |37 |\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 |47.403372044054 |8.486123978826 |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |149 |Bus |38 |\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 |47.4057006674825|8.48137189097235|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |690 |Bus |39 |\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 |47.4055243523393|8.47408655401713|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1329 |Bus |40 |\n", "|26-304-j19-1 |8590726 |159.TA.26-304-j19-1.4.R |8590726|19:48:00 |19:48:00 |8 |Oberengstringen, Lanzrain |47.407342193939 |8.46795106062573|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |763 |Bus |41 |\n", "|26-304-j19-1 |8590728 |159.TA.26-304-j19-1.4.R |8590728|19:49:00 |19:49:00 |9 |Oberengstringen, Zentrum |47.4091295756792|8.46260608468448|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |376 |Bus |42 |\n", "|26-304-j19-1 |8590727 |159.TA.26-304-j19-1.4.R |8590727|19:50:00 |19:50:00 |10 |Oberengstringen, Paradies |47.4104852703573|8.45874332896223|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |740 |Bus |43 |\n", "|26-304-j19-1 |8590833 |159.TA.26-304-j19-1.4.R |8590833|19:51:00 |19:51:00 |11 |Unterengstringen, Langacher |47.4122360710415|8.45316479104707|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |764 |Bus |44 |\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|47.4134944230824|8.44931101847766|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |987 |Bus |45 |\n", "|26-304-j19-1 |8590831 |159.TA.26-304-j19-1.4.R |8590831|19:53:00 |19:53:00 |13 |Unterengstringen, Aegelsee |47.414977659342 |8.44603216769017|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |502 |Bus |46 |\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 |47.4176826342903|8.43953734818508|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |754 |Bus |47 |\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 |47.4195547602987|8.43394084396424|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |934 |Bus |48 |\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 |47.4183512583635|8.42866773324572|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |622 |Bus |49 |\n", "|26-304-j19-1 |8590617 |159.TA.26-304-j19-1.4.R |8590617|19:59:00 |19:59:00 |17 |Geroldswil, Welbrig |47.4180716529658|8.41906474285715|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |859 |Bus |50 |\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 |47.4256326325821|8.49799970688372|Zürich, Schwamendingerplatz|2076 |0 |19:57:00 |3 |2 |212 |Bus |51 |\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 |47.425085652811 |8.50058685490234|Zürich, Schwamendingerplatz|2076 |0 |19:57:00 |3 |2 |1003 |Bus |52 |\n", "|26-703-j19-1 |8591825 |179.TA.26-703-j19-1.2.R |8591825|07:10:00 |07:10:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |580 |Bus |53 |\n", "|26-703-j19-1 |8590504 |179.TA.26-703-j19-1.2.R |8590504|07:11:00 |07:11:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |861 |Bus |54 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1366 |Bus |55 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1023 |Bus |56 |\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 |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1260 |Bus |57 |\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 |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |146 |Bus |58 |\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 |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1197 |Bus |59 |\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|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1311 |Bus |60 |\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 |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1133 |Bus |61 |\n", "|26-703-j19-1 |8591825 |171.TA.26-703-j19-1.2.R |8591825|07:12:00 |07:12:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |580 |Bus |62 |\n", "|26-703-j19-1 |8590504 |171.TA.26-703-j19-1.2.R |8590504|07:13:00 |07:13:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |861 |Bus |63 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1366 |Bus |64 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1023 |Bus |65 |\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 |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1260 |Bus |66 |\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 |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |146 |Bus |67 |\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 |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1197 |Bus |68 |\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|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1311 |Bus |69 |\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 |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1133 |Bus |70 |\n", "|26-703-j19-1 |8591825 |156.TA.26-703-j19-1.2.R |8591825|07:25:00 |07:25:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |580 |Bus |71 |\n", "|26-703-j19-1 |8590504 |156.TA.26-703-j19-1.2.R |8590504|07:26:00 |07:26:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |861 |Bus |72 |\n", "|26-703-j19-1 |8596005 |156.TA.26-703-j19-1.2.R |8596005|07:29:00 |07:29:00 |3 |Binz bei Maur, Twäracher |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1366 |Bus |73 |\n", "|26-703-j19-1 |8591832 |156.TA.26-703-j19-1.2.R |8591832|07:29:00 |07:29:00 |4 |Pfaffhausen, Müseren |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1023 |Bus |74 |\n", "|26-703-j19-1 |8591147 |156.TA.26-703-j19-1.2.R |8591147|07:31:00 |07:31:00 |5 |Zürich, Friedhof Witikon |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1260 |Bus |75 |\n", "|26-703-j19-1 |8591162 |156.TA.26-703-j19-1.2.R |8591162|07:32:00 |07:32:00 |6 |Zürich, Glockenacker |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |146 |Bus |76 |\n", "|26-703-j19-1 |8591261 |156.TA.26-703-j19-1.2.R |8591261|07:33:00 |07:33:00 |7 |Zürich, Loorenstrasse |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1197 |Bus |77 |\n", "|26-703-j19-1 |8591107 |156.TA.26-703-j19-1.2.R |8591107|07:34:00 |07:34:00 |8 |Zürich, Carl-Spitteler-Strasse|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1311 |Bus |78 |\n", "|26-703-j19-1 |8591233 |156.TA.26-703-j19-1.2.R |8591233|07:40:00 |07:40:00 |9 |Zürich, Klusplatz |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1133 |Bus |79 |\n", "|26-703-j19-1 |8591825 |144.TA.26-703-j19-1.2.R |8591825|07:27:00 |07:27:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |580 |Bus |80 |\n", "|26-703-j19-1 |8590504 |144.TA.26-703-j19-1.2.R |8590504|07:28:00 |07:28:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |861 |Bus |81 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1366 |Bus |82 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1023 |Bus |83 |\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 |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1260 |Bus |84 |\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 |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |146 |Bus |85 |\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 |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1197 |Bus |86 |\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|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1311 |Bus |87 |\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 |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1133 |Bus |88 |\n", "|26-703-j19-1 |8591825 |120.TA.26-703-j19-1.2.R |8591825|07:40:00 |07:40:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |580 |Bus |89 |\n", "|26-703-j19-1 |8590504 |120.TA.26-703-j19-1.2.R |8590504|07:41:00 |07:41:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |861 |Bus |90 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1366 |Bus |91 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1023 |Bus |92 |\n", "|26-703-j19-1 |8591147 |120.TA.26-703-j19-1.2.R |8591147|07:46:00 |07:46:00 |5 |Zürich, Friedhof Witikon |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1260 |Bus |93 |\n", "|26-703-j19-1 |8591162 |120.TA.26-703-j19-1.2.R |8591162|07:47:00 |07:47:00 |6 |Zürich, Glockenacker |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |146 |Bus |94 |\n", "|26-703-j19-1 |8591261 |120.TA.26-703-j19-1.2.R |8591261|07:48:00 |07:48:00 |7 |Zürich, Loorenstrasse |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1197 |Bus |95 |\n", "|26-703-j19-1 |8591107 |120.TA.26-703-j19-1.2.R |8591107|07:49:00 |07:49:00 |8 |Zürich, Carl-Spitteler-Strasse|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1311 |Bus |96 |\n", "|26-703-j19-1 |8591233 |120.TA.26-703-j19-1.2.R |8591233|07:55:00 |07:55:00 |9 |Zürich, Klusplatz |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1133 |Bus |97 |\n", "|26-703-j19-1 |8591825 |95.TA.26-703-j19-1.2.R |8591825|07:42:00 |07:42:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9119 |1 |07:42:00 |4 |9 |580 |Bus |98 |\n", "|26-703-j19-1 |8590504 |95.TA.26-703-j19-1.2.R |8590504|07:43:00 |07:43:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9119 |1 |07:42:00 |4 |9 |861 |Bus |99 |\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", ".withColumn('monotonically_increasing_id', F.monotonically_increasing_id())\n", "\n", "stop_times.show(100, 0)" ] }, { "cell_type": "code", "execution_count": 73, "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": [ "# 10 Footpaths\n", "\n", "We make the simplifying assumption that within stops sharing the same 7 first characters (`stop_id_general`) (almost the same as grouping them by parent stations, but more robust), transfer times take 2 minutes, no matter the stop. This may break for very large stations (such as Zürich HB).\n", "\n", "Between different `stop_id_general`, walking time is computed as the distance (which must be max. 500m) divided by a constant walking speed of 50 meters per minute.\n", "\n", "We only consider stops present in the final and filtered `stop_times` table.\n", "\n", "- get all unique `stop_int` with a single pair of coordinates\n", "- cross-join two copies of this dataframe. The result is all permutations of `stop_int` pairs\n", "- drop pairs where `general_stop_id` is the same\n", "- compute the bird's fly distance with geopy for all other pairs of `stop_int` using GPS coordinates\n", "- filter out pairs of stops with a distance greater than 500 meters\n", "- transform distance to walking time in seconds\n", "- order by `stop_int1`, then `stop_int2` to mimic the data structure Transfers in RAPTOR\n", "- create a monotonically increasing ID to easily sort on this table after reading from a distributed file system" ] }, { "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" } ], "source": [ "stop_times = spark.read.csv('data/lgpt_guys/stop_times_final_cyril.csv', header=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Getting one pair of coordinates per parent stop:" ] }, { "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": [ "+---------------+----------------+----------------+--------------------+\n", "|stop_id_general| stop_lat| stop_lon| stop_name|\n", "+---------------+----------------+----------------+--------------------+\n", "| 8576163|47.4446882894765|8.63618754705906| Bassersdorf, Rietli|\n", "| 8588279|47.4314059613092|8.66796994181563|Tagelswangen, Ger...|\n", "| 8588740|47.4448766240902|8.57874926778446|Kloten, Neubrunne...|\n", "| 8595714|47.4485885009565|8.45665025434994| Regensdorf, Allmend|\n", "| 8588054|47.3600457522121|8.71459250506792| Uster, Meieracher|\n", "| 8590851|47.3894589587793|8.67489595265716|Volketswil, Chappeli|\n", "| 8591345|47.3845933768342|8.47776964668253|Zürich, Schulhaus...|\n", "| 8591264|47.4060107375098|8.58139031472014| Zürich, Luegisland|\n", "| 8503202|47.2960953402584|8.56475351565593| Thalwil|\n", "| 8573163|47.2857066724744|8.55511459265598|Gattikon, Gattike...|\n", "| 8590795|47.3955220616337|8.46779834702741| Schlieren, Mülligen|\n", "| 8590652|47.2544735496734|8.60926503799025|Horgen, Glärnischhof|\n", "| 8594307|47.4384910970626|8.36438429150518|Würenlos, Lärchenweg|\n", "| 8591110|47.3884919601296|8.52639545301869| Zürich, Dammweg|\n", "| 8591052|47.3783343616704|8.52287405710445|Zürich, Bäckeranlage|\n", "| 8582529|47.3522623481765|8.35006514587432|Bremgarten AG, Zu...|\n", "| 8591319|47.4106433311425| 8.5592648092692| Zürich, Riedgraben|\n", "| 8502221|47.3574960379336|8.43754308825406| Birmensdorf ZH|\n", "| 8591438|47.3591816623693|8.58524408728955|Zürich, Witikon Z...|\n", "| 8590473|47.3151369463988|8.53576488143336|Adliswil, Hofacke...|\n", "+---------------+----------------+----------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times.select(stop_times.stop_id_general, stop_times.stop_lat, stop_times.stop_lon, stop_times.stop_name).dropDuplicates()\\\n", ".show()" ] }, { "cell_type": "code", "execution_count": 76, "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(\"stop_id_general\")\n", " .orderBy('stop_name')\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", "|stop_id_general|stop_int| stop_lat_first| stop_lon_first| stop_name_first|\n", "+---------------+--------+----------------+----------------+--------------------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU|\n", "| 8503376| 8|47.4353132339136| 8.7169371079598|Ottikon b. Kemptthal|\n", "| 8587967| 7|47.2955835709855|8.60393802835468|Erlenbach ZH, Im ...|\n", "| 8589111| 5| 47.260856991692|8.59230484542371|Horgen, Gumelenst...|\n", "| 8590819| 6|47.2821844204798|8.57300004996529| Thalwil, Mettli|\n", "| 8591190| 4|47.3694098744442|8.50635403902719| Zürich, Heuried|\n", "| 8591284| 3|47.3909246273101|8.47396977303017| Zürich, Neeserweg|\n", "| 8588312| 9|47.4329251530902|8.68904441838401|Effretikon, Kapel...|\n", "| 8590541| 10|47.4165824252901|8.61689173475348|Dietlikon, Dornen...|\n", "| 8590804| 14|47.3972672788911|8.44748743845064| Schlieren, Zentrum|\n", "| 8591149| 12|47.3642868894025|8.50799795599736| Zürich, Friesenberg|\n", "| 8591315| 13|47.3510268782417|8.58298033277325| Zürich, Rehalp|\n", "| 8591362| 11|47.3859132103277|8.54836824487131|Zürich, Seilbahn ...|\n", "| 8580432| 21|47.4439106426415|8.57842587428213| Kloten, Bramen|\n", "| 8590273| 16|47.4263923172796|8.36551616876333|Spreitenbach, Fur...|\n", "| 8590477| 15|47.3254528526241|8.53104872619107| Adliswil, Moos|\n", "| 8591053| 22|47.4058952214384|8.53778609082291|Zürich, Bad Allen...|\n", "| 8591080| 18| 47.347588102752|8.53434554328425|Zürich Wollishofe...|\n", "+---------------+--------+----------------+----------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "from pyspark.sql import functions as F\n", "\n", "stop_coordinates = stop_times.select(stop_times.stop_id_general, stop_times.stop_int, stop_times.stop_lat, stop_times.stop_lon, stop_times.stop_name,\n", " F.first(\"stop_lat\").over(w).alias(\"stop_lat_first\"),\n", " F.first(\"stop_lon\").over(w).alias(\"stop_lon_first\"),\n", " F.first(\"stop_name\").over(w).alias(\"stop_name_first\"))\\\n", ".select(F.col('stop_id_general'), F.col('stop_int'), F.col('stop_lat_first'), F.col(\"stop_lon_first\"), F.col(\"stop_name_first\"))\\\n", ".dropDuplicates()\\\n", "\n", "stop_coordinates.show()" ] }, { "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" }, { "name": "stdout", "output_type": "stream", "text": [ "1407" ] } ], "source": [ "stop_coordinates.count()" ] }, { "cell_type": "code", "execution_count": 79, "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_2|stop_int_2|stop_lat_first_2|stop_lon_first_2| stop_name_first_2|\n", "+-----------------+----------+----------------+----------------+--------------------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU|\n", "| 8503376| 8|47.4353132339136| 8.7169371079598|Ottikon b. Kemptthal|\n", "| 8587967| 7|47.2955835709855|8.60393802835468|Erlenbach ZH, Im ...|\n", "| 8589111| 5| 47.260856991692|8.59230484542371|Horgen, Gumelenst...|\n", "| 8590819| 6|47.2821844204798|8.57300004996529| Thalwil, Mettli|\n", "| 8591190| 4|47.3694098744442|8.50635403902719| Zürich, Heuried|\n", "| 8591284| 3|47.3909246273101|8.47396977303017| Zürich, Neeserweg|\n", "| 8588312| 9|47.4329251530902|8.68904441838401|Effretikon, Kapel...|\n", "| 8590541| 10|47.4165824252901|8.61689173475348|Dietlikon, Dornen...|\n", "| 8590804| 14|47.3972672788911|8.44748743845064| Schlieren, Zentrum|\n", "| 8591149| 12|47.3642868894025|8.50799795599736| Zürich, Friesenberg|\n", "| 8591315| 13|47.3510268782417|8.58298033277325| Zürich, Rehalp|\n", "| 8591362| 11|47.3859132103277|8.54836824487131|Zürich, Seilbahn ...|\n", "| 8580432| 21|47.4439106426415|8.57842587428213| Kloten, Bramen|\n", "| 8590273| 16|47.4263923172796|8.36551616876333|Spreitenbach, Fur...|\n", "| 8590477| 15|47.3254528526241|8.53104872619107| Adliswil, Moos|\n", "| 8591053| 22|47.4058952214384|8.53778609082291|Zürich, Bad Allen...|\n", "| 8591080| 18| 47.347588102752|8.53434554328425|Zürich Wollishofe...|\n", "+-----------------+----------+----------------+----------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_coordinates_for_join = stop_coordinates.select(stop_coordinates.stop_id_general.alias('stop_id_general_2'),\n", " stop_coordinates.stop_int.alias('stop_int_2'),\n", " stop_coordinates.stop_lat_first.alias('stop_lat_first_2'),\n", " stop_coordinates.stop_lon_first.alias('stop_lon_first_2'),\n", " stop_coordinates.stop_name_first.alias('stop_name_first_2'))\n", "stop_coordinates_for_join.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We perform a cross-join (every possible combination of row gets created), then drop every row where the stop_id is the same." ] }, { "cell_type": "code", "execution_count": 80, "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|stop_int| stop_lat_first| stop_lon_first| stop_name_first|stop_id_general_2|stop_int_2|stop_lat_first_2|stop_lon_first_2| stop_name_first_2|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503376| 8|47.4353132339136| 8.7169371079598|Ottikon b. Kemptthal|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8587967| 7|47.2955835709855|8.60393802835468|Erlenbach ZH, Im ...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8589111| 5| 47.260856991692|8.59230484542371|Horgen, Gumelenst...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590819| 6|47.2821844204798|8.57300004996529| Thalwil, Mettli|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591190| 4|47.3694098744442|8.50635403902719| Zürich, Heuried|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591284| 3|47.3909246273101|8.47396977303017| Zürich, Neeserweg|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8588312| 9|47.4329251530902|8.68904441838401|Effretikon, Kapel...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590541| 10|47.4165824252901|8.61689173475348|Dietlikon, Dornen...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590804| 14|47.3972672788911|8.44748743845064| Schlieren, Zentrum|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591149| 12|47.3642868894025|8.50799795599736| Zürich, Friesenberg|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591315| 13|47.3510268782417|8.58298033277325| Zürich, Rehalp|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591362| 11|47.3859132103277|8.54836824487131|Zürich, Seilbahn ...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8580432| 21|47.4439106426415|8.57842587428213| Kloten, Bramen|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590273| 16|47.4263923172796|8.36551616876333|Spreitenbach, Fur...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590477| 15|47.3254528526241|8.53104872619107| Adliswil, Moos|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591053| 22|47.4058952214384|8.53778609082291|Zürich, Bad Allen...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591080| 18| 47.347588102752|8.53434554328425|Zürich Wollishofe...|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591085| 17|47.4274011616099|8.54614042296638|Zürich, Birch-/Gl...|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_coordinates_cross = stop_coordinates.crossJoin(stop_coordinates_for_join)\\\n", ".filter(F.col('stop_id_general')!=F.col('stop_id_general_2'))\n", "stop_coordinates_cross.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we compute the distance in meters, as well as the time in seconds it takes to walk this distance" ] }, { "cell_type": "code", "execution_count": 81, "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|stop_int| stop_lat_first| stop_lon_first| stop_name_first|stop_id_general_2|stop_int_2|stop_lat_first_2|stop_lon_first_2| stop_name_first_2| distance|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+---------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg|18.017555|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU|12.902226|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503376| 8|47.4353132339136| 8.7169371079598|Ottikon b. Kemptthal| 25.65447|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8587967| 7|47.2955835709855|8.60393802835468|Erlenbach ZH, Im ...|21.665598|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8589111| 5| 47.260856991692|8.59230484542371|Horgen, Gumelenst...|23.627174|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+---------+\n", "only showing top 5 rows" ] } ], "source": [ "# adding distance\n", "stop_coordinates_cross_distance = stop_coordinates_cross.withColumn(\"distance\", \\\n", " great_circle_udf(struct(stop_coordinates_cross.stop_lat_first, stop_coordinates_cross.stop_lon_first), \\\n", " struct(stop_coordinates_cross.stop_lat_first_2, stop_coordinates_cross.stop_lon_first_2)))\n", "stop_coordinates_cross_distance.show(5)" ] }, { "cell_type": "code", "execution_count": 82, "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|stop_int| stop_lat_first| stop_lon_first| stop_name_first|stop_id_general_2|stop_int_2|stop_lat_first_2|stop_lon_first_2| stop_name_first_2| distance|walking_time|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+----------+------------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg| 18.017555| 21621|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 12.902226| 15482|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8503376| 8|47.4353132339136| 8.7169371079598|Ottikon b. Kemptthal| 25.65447| 30785|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8587967| 7|47.2955835709855|8.60393802835468|Erlenbach ZH, Im ...| 21.665598| 25998|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8589111| 5| 47.260856991692|8.59230484542371|Horgen, Gumelenst...| 23.627174| 28352|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590819| 6|47.2821844204798|8.57300004996529| Thalwil, Mettli| 20.909445| 25091|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591190| 4|47.3694098744442|8.50635403902719| Zürich, Heuried| 10.988478| 13186|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591284| 3|47.3909246273101|8.47396977303017| Zürich, Neeserweg| 7.7776713| 9333|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8588312| 9|47.4329251530902|8.68904441838401|Effretikon, Kapel...| 23.541742| 28250|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590541| 10|47.4165824252901|8.61689173475348|Dietlikon, Dornen...| 18.036524| 21643|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590804| 14|47.3972672788911|8.44748743845064| Schlieren, Zentrum| 5.663664| 6796|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591149| 12|47.3642868894025|8.50799795599736| Zürich, Friesenberg| 11.372528| 13647|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591315| 13|47.3510268782417|8.58298033277325| Zürich, Rehalp| 17.069794| 20483|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591362| 11|47.3859132103277|8.54836824487131|Zürich, Seilbahn ...|13.2958765| 15955|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8580432| 21|47.4439106426415|8.57842587428213| Kloten, Bramen| 15.46525| 18558|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590273| 16|47.4263923172796|8.36551616876333|Spreitenbach, Fur...| 1.5007852| 1800|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590477| 15|47.3254528526241|8.53104872619107| Adliswil, Moos| 15.309975| 18371|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591053| 22|47.4058952214384|8.53778609082291|Zürich, Bad Allen...|12.1317835| 14558|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591080| 18| 47.347588102752|8.53434554328425|Zürich Wollishofe...| 14.033888| 16840|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8591085| 17|47.4274011616099|8.54614042296638|Zürich, Birch-/Gl...| 12.780608| 15336|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+----------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_coordinates_cross_distance_time = stop_coordinates_cross_distance.withColumn('walking_time', \n", " (F.col('distance')/0.05*60).cast('int'))\n", "stop_coordinates_cross_distance_time.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Removing pairs of stops more than 500 meters (0.5 km) away" ] }, { "cell_type": "code", "execution_count": 83, "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|stop_int| stop_lat_first| stop_lon_first| stop_name_first|stop_id_general_2|stop_int_2|stop_lat_first_2|stop_lon_first_2| stop_name_first_2| distance|walking_time|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+-----------+------------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590268| 815|47.4142117310803| 8.3795209040447| Spreitenbach, ASP| 0.22296342| 267|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590270| 1350|47.4179500849385|8.37208285349115| Spreitenbach, Brüel| 0.4742755| 569|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg| 8591903| 63|47.3483489130904|8.59604183700617|Zollikerberg, Spital| 0.39212397| 470|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg| 8591023| 242|47.3468211948325|8.59815287792414|Zollikerb., Langä...| 0.41439477| 497|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg| 8590879| 551|47.3453908209261|8.59330197538922| Waldburg, Station|0.023021813| 27|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg| 8503077| 705|47.3473202949034|8.59679642184493| Spital Zollikerberg| 0.35051093| 420|\n", "| 8503078| 1|47.3454760357765| 8.5930234976511| Waldburg| 8576189| 1001|47.3457012457904|8.58848700546567|Zollikon, Rebwies...| 0.34270898| 411|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591327| 48|47.3743498590472|8.54323886459827|Zürich, Rudolf-Br...| 0.46496668| 557|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8588078| 272|47.3768440104406|8.54393955051998| Zürich, Central| 0.36639458| 439|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591316| 373|47.3730662375955|8.53845982728609| Zürich, Rennweg| 0.4953369| 594|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591367| 461|47.3760957774096|8.53420181283877| Zürich, Sihlpost/HB| 0.40512198| 486|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8587349| 602|47.3775618175159|8.54173867807358|Zürich, Bahnhofqu...| 0.19359568| 232|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591067| 616|47.3765581015114|8.53994204750509|Zürich, Bahnhofst...| 0.11930997| 143|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8503446| 785|47.3788453295376|8.54171172861506| Zürich Landesmuseum| 0.24329051| 291|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 0.42122737| 505|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591368| 880|47.3798733332196|8.53760642776606| Zürich, Sihlquai/HB| 0.28947487| 347|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591174| 947|47.3796482690385| 8.5445144723019| Zürich, Haldenegg| 0.46829802| 561|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591379| 1033| 47.379958492389|8.54280767326183|Zürich, Stampfenb...| 0.38740817| 464|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8503000| 1173|47.3782978637762|8.54019357578468| Zürich HB| 0.1179737| 141|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8587348| 1196|47.3772394138519|8.53934017626465|Zürich, Bahnhofpl...|0.031180955| 37|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+-----------+------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_coordinates_cross_distance_time_filtered = stop_coordinates_cross_distance_time.filter(F.col('distance')<=0.5)\n", "stop_coordinates_cross_distance_time_filtered.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sorting by stop_int, then stop_int 2 to sort it as `transfers` in RAPTOR." ] }, { "cell_type": "code", "execution_count": 84, "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_coordinates_cross_distance_time_filtered_sorted = stop_coordinates_cross_distance_time_filtered.sort(F.col('stop_int').cast('int'), F.col('stop_int_2').cast('int'))\\\n", ".withColumn('monotonically_increasing_id', F.monotonically_increasing_id())" ] }, { "cell_type": "code", "execution_count": 85, "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_coordinates_cross_distance_time_filtered_sorted.write.csv('data/lgpt_guys/transfers_cyril.csv', header=True, mode='overwrite')" ] }, { "cell_type": "code", "execution_count": 86, "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_coordinates_cross_distance_time_filtered_sorted = spark.read.csv('data/lgpt_guys/transfers_cyril.csv', header=True)" ] }, { "cell_type": "code", "execution_count": 87, "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": [ "6264" ] } ], "source": [ "stop_coordinates_cross_distance_time_filtered_sorted.count()" ] }, { "cell_type": "code", "execution_count": 88, "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|stop_int| stop_lat_first| stop_lon_first| stop_name_first|stop_id_general_2|stop_int_2|stop_lat_first_2|stop_lon_first_2| stop_name_first_2| distance|walking_time|monotonically_increasing_id|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+----------+------------+---------------------------+\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590268| 815|47.4142117310803| 8.3795209040447| Spreitenbach, ASP|0.22296342| 267| 0|\n", "| 8502508| 0|47.4154457211288|8.37718528430566|Spreitenbach, Rai...| 8590270| 1350|47.4179500849385|8.37208285349115| Spreitenbach, Brüel| 0.4742755| 569| 1|\n", "| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU| 8591367| 461|47.3760957774096|8.53420181283877| Zürich, Sihlpost/HB|0.40512198| 486| 10|\n", "| 8590474| 819|47.3129444045737|8.52782377432064| Adliswil, Krone| 8595717| 1241|47.3129504950936|8.53005159622556|Adliswil, Grundst...|0.16795586| 201| 1005022347264|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8503088| 2|47.3774949037101|8.53916949636064| Zürich HB SZU|0.42122737| 505| 1005022347265|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8591282| 138|47.3821239221899|8.53493843137185|Zürich, Museum fü...| 0.2132881| 255| 1005022347266|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8591071| 543|47.3840824646745|8.54044510406427| Zürich, Beckenhof| 0.4105776| 492| 1005022347267|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8503446| 785|47.3788453295376|8.54171172861506| Zürich Landesmuseum| 0.413811| 496| 1005022347268|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8591368| 880|47.3798733332196|8.53760642776606| Zürich, Sihlquai/HB|0.13454837| 161| 1005022347269|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8591379| 1033| 47.379958492389|8.54280767326183|Zürich, Stampfenb...|0.43250278| 519| 1005022347270|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8503000| 1173|47.3782978637762|8.54019357578468| Zürich HB|0.37702298| 452| 1005022347271|\n", "| 8596126| 820|47.3810655490734|8.53730100056942| Zürich, Bus Station| 8587348| 1196|47.3772394138519|8.53934017626465|Zürich, Bahnhofpl...| 0.4523052| 542| 1005022347272|\n", "| 8591354| 821|47.4218644344265|8.54977859986757| Zürich, Seebach| 8591048| 160|47.4245143567597| 8.548556891081|Zürich, Ausserdor...| 0.3086605| 370| 1005022347273|\n", "| 8591354| 821|47.4218644344265|8.54977859986757| Zürich, Seebach| 8591355| 273| 47.419864748766|8.54836824487131|Zürich, Seebacher...|0.24637553| 295| 1005022347274|\n", "| 8591354| 821|47.4218644344265|8.54977859986757| Zürich, Seebach| 8591187| 940|47.4228794433749|8.54349039287786|Zürich, Hertenste...|0.48635942| 583| 1005022347275|\n", "| 8591354| 821|47.4218644344265|8.54977859986757| Zürich, Seebach| 8591124| 1250|47.4254624617068|8.55363237243698| Zürich, Ettenfeld| 0.4940879| 592| 1005022347276|\n", "| 8591407| 822|47.4245872885157|8.51184274541392|Zürich, Unteraffo...| 8503008| 211|47.4210317478027|8.50856389462643| Zürich Affoltern|0.46600202| 559| 1005022347277|\n", "| 8591407| 822|47.4245872885157|8.51184274541392|Zürich, Unteraffo...| 8591153| 465|47.4219616816404|8.51004611484544| Zürich, Fronwald|0.32172477| 386| 1005022347278|\n", "| 8591062| 824|47.4125400235641|8.54190935797759|Zürich Oerlikon, ...| 8591272| 82|47.4140476021462|8.54133443619567|Zürich, Max-Bill-...| 0.1731274| 207| 1005022347279|\n", "| 8591062| 824|47.4125400235641|8.54190935797759|Zürich Oerlikon, ...| 8591063| 357| 47.413336370854|8.54584397892258|Zürich Oerlikon, ...| 0.3090261| 370| 1005022347280|\n", "+---------------+--------+----------------+----------------+--------------------+-----------------+----------+----------------+----------------+--------------------+----------+------------+---------------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_coordinates_cross_distance_time_filtered_sorted.sort(F.col('monotonically_increasing_id')).show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 11 Verifying a few routes and trips on real data" ] }, { "cell_type": "code", "execution_count": 111, "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|arrival_time|departure_time|monotonically_increasing_id|\n", "+---------+------------+--------------+---------------------------+\n", "| 0| 07:00:00| 07:00:00| 0|\n", "| 0| 07:01:00| 07:01:00| 1|\n", "| 0| 07:02:00| 07:02:00| 2|\n", "| 0| 07:03:00| 07:03:00| 3|\n", "| 0| 07:05:00| 07:05:00| 4|\n", "| 0| 07:06:00| 07:06:00| 5|\n", "| 0| 07:08:00| 07:08:00| 6|\n", "| 0| 07:09:00| 07:09:00| 7|\n", "| 0| 07:10:00| 07:10:00| 8|\n", "| 0| 07:11:00| 07:11:00| 9|\n", "| 0| 07:12:00| 07:12:00| 10|\n", "| 0| 07:14:00| 07:14:00| 11|\n", "| 0| 07:16:00| 07:16:00| 12|\n", "| 0| 07:18:00| 07:18:00| 13|\n", "| 0| 07:20:00| 07:20:00| 14|\n", "| 0| 07:22:00| 07:22:00| 15|\n", "| 0| 07:23:00| 07:23:00| 16|\n", "| 0| 07:24:00| 07:24:00| 17|\n", "| 0| 07:25:00| 07:25:00| 18|\n", "| 0| 07:27:00| 07:27:00| 19|\n", "+---------+------------+--------------+---------------------------+\n", "only showing top 20 rows" ] } ], "source": [ "stop_times = spark.read.csv('data/lgpt_guys/stop_times_final_cyril.csv', header=True)\n", "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", ".select(stop_times.route_int, stop_times.arrival_time, stop_times.departure_time, stop_times.monotonically_increasing_id)\\\n", ".show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Casting spark's `monotonically_increasing_id` as `LongType` (and not `IntegerType`) is paramount to make sure the sort happens as expected. Otherwise, there are not enough bytes to represent the index as an integer." ] }, { "cell_type": "code", "execution_count": 122, "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 |stop_lat |stop_lon |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|monotonically_increasing_id|\n", "+-------------+---------------+------------------------+-------+------------+--------------+-------------+------------------------------+----------------+----------------+---------------------------+---------------+------------+--------------------+---------+----------+--------+----------+---------------------------+\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 |47.4020100860391|8.49937412926861|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1221 |Tram |0 |\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 |47.3997299435837|8.50461130737576|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |816 |Tram |1 |\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 |47.3977659017765|8.50725235431143|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |776 |Tram |2 |\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 |47.3962700189648|8.51204037477646|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |307 |Tram |3 |\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 |47.3954977376399|8.51840044698891|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |347 |Tram |4 |\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 |47.3925909395293|8.52357474302616|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1015 |Tram |5 |\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 |47.3907969150758|8.5223979500038 |Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |455 |Tram |6 |\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 |47.3884919601296|8.52639545301869|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1102 |Tram |7 |\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 |47.3867403702341|8.52874903906341|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |786 |Tram |8 |\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 |47.3845994590919|8.53162364797299|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |388 |Tram |9 |\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 |47.3821239221899|8.53493843137185|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |138 |Tram |10 |\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 |47.3798733332196|8.53760642776606|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |880 |Tram |11 |\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 |47.3775618175159|8.54173867807358|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |602 |Tram |12 |\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 |47.3765581015114|8.53994204750509|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |616 |Tram |13 |\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 |47.3730662375955|8.53845982728609|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |373 |Tram |14 |\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 |47.3693672863583|8.53876525448273|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1223 |Tram |15 |\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 |47.3677002399791|8.53501029659459|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |871 |Tram |16 |\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 |47.3661426599847|8.53253094641008|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |890 |Tram |17 |\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.|47.3645546111557|8.53045583810347|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |177 |Tram |18 |\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 |47.3614818138862|8.52574866601403|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1265 |Tram |19 |\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 |47.3600640074787|8.52303575385561|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |968 |Tram |20 |\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 |47.3578611597087|8.52040369007277|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1238 |Tram |21 |\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 |47.3587313564196|8.51708890667391|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1216 |Tram |22 |\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 |47.3567353594536|8.51396276948474|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |847 |Tram |23 |\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 |47.3530717783138|8.51171698127413|Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |275 |Tram |24 |\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 |47.3519945640447|8.5077104951064 |Zürich, Albisgütli |1831 |0 |07:00:00 |0 |26 |1352 |Tram |25 |\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 |47.4166918393693|8.568113214819 |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |1117 |Tram |26 |\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 |47.4181749855684|8.56174415945371|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |156 |Tram |27 |\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 |47.4199559214972|8.55716275150406|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |671 |Tram |28 |\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 |47.4175853791724|8.5542072942189 |Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |573 |Tram |29 |\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 |47.4146433269471|8.55130573585079|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |444 |Tram |30 |\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 |47.4106919651348|8.55068589830466|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |389 |Tram |31 |\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 |47.4100718783688|8.54623025449481|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |687 |Tram |32 |\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 |47.411494419524 |8.54479295004002|Zürich, Rehalp |363 |0 |19:49:00 |1 |8 |766 |Tram |33 |\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 |47.392067942097 |8.48990588617267|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |521 |Bus |34 |\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 |47.3979787271809|8.49434356367684|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1000 |Bus |35 |\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 |47.4000582901792|8.4945681424979 |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |711 |Bus |36 |\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 |47.4013473348052|8.49021131336931|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1125 |Bus |37 |\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 |47.403372044054 |8.486123978826 |Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |149 |Bus |38 |\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 |47.4057006674825|8.48137189097235|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |690 |Bus |39 |\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 |47.4055243523393|8.47408655401713|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |1329 |Bus |40 |\n", "|26-304-j19-1 |8590726 |159.TA.26-304-j19-1.4.R |8590726|19:48:00 |19:48:00 |8 |Oberengstringen, Lanzrain |47.407342193939 |8.46795106062573|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |763 |Bus |41 |\n", "|26-304-j19-1 |8590728 |159.TA.26-304-j19-1.4.R |8590728|19:49:00 |19:49:00 |9 |Oberengstringen, Zentrum |47.4091295756792|8.46260608468448|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |376 |Bus |42 |\n", "|26-304-j19-1 |8590727 |159.TA.26-304-j19-1.4.R |8590727|19:50:00 |19:50:00 |10 |Oberengstringen, Paradies |47.4104852703573|8.45874332896223|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |740 |Bus |43 |\n", "|26-304-j19-1 |8590833 |159.TA.26-304-j19-1.4.R |8590833|19:51:00 |19:51:00 |11 |Unterengstringen, Langacher |47.4122360710415|8.45316479104707|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |764 |Bus |44 |\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|47.4134944230824|8.44931101847766|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |987 |Bus |45 |\n", "|26-304-j19-1 |8590831 |159.TA.26-304-j19-1.4.R |8590831|19:53:00 |19:53:00 |13 |Unterengstringen, Aegelsee |47.414977659342 |8.44603216769017|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |502 |Bus |46 |\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 |47.4176826342903|8.43953734818508|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |754 |Bus |47 |\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 |47.4195547602987|8.43394084396424|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |934 |Bus |48 |\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 |47.4183512583635|8.42866773324572|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |622 |Bus |49 |\n", "|26-304-j19-1 |8590617 |159.TA.26-304-j19-1.4.R |8590617|19:59:00 |19:59:00 |17 |Geroldswil, Welbrig |47.4180716529658|8.41906474285715|Dietikon, Bahnhof |5481 |1 |19:39:00 |2 |17 |859 |Bus |50 |\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 |47.4256326325821|8.49799970688372|Zürich, Schwamendingerplatz|2076 |0 |19:57:00 |3 |2 |212 |Bus |51 |\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 |47.425085652811 |8.50058685490234|Zürich, Schwamendingerplatz|2076 |0 |19:57:00 |3 |2 |1003 |Bus |52 |\n", "|26-703-j19-1 |8591825 |179.TA.26-703-j19-1.2.R |8591825|07:10:00 |07:10:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |580 |Bus |53 |\n", "|26-703-j19-1 |8590504 |179.TA.26-703-j19-1.2.R |8590504|07:11:00 |07:11:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |861 |Bus |54 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1366 |Bus |55 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1023 |Bus |56 |\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 |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1260 |Bus |57 |\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 |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |146 |Bus |58 |\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 |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1197 |Bus |59 |\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|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1311 |Bus |60 |\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 |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9385 |1 |07:10:00 |4 |9 |1133 |Bus |61 |\n", "|26-703-j19-1 |8591825 |171.TA.26-703-j19-1.2.R |8591825|07:12:00 |07:12:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |580 |Bus |62 |\n", "|26-703-j19-1 |8590504 |171.TA.26-703-j19-1.2.R |8590504|07:13:00 |07:13:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |861 |Bus |63 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1366 |Bus |64 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1023 |Bus |65 |\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 |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1260 |Bus |66 |\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 |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |146 |Bus |67 |\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 |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1197 |Bus |68 |\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|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1311 |Bus |69 |\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 |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9346 |1 |07:12:00 |4 |9 |1133 |Bus |70 |\n", "|26-703-j19-1 |8591825 |156.TA.26-703-j19-1.2.R |8591825|07:25:00 |07:25:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |580 |Bus |71 |\n", "|26-703-j19-1 |8590504 |156.TA.26-703-j19-1.2.R |8590504|07:26:00 |07:26:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |861 |Bus |72 |\n", "|26-703-j19-1 |8596005 |156.TA.26-703-j19-1.2.R |8596005|07:29:00 |07:29:00 |3 |Binz bei Maur, Twäracher |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1366 |Bus |73 |\n", "|26-703-j19-1 |8591832 |156.TA.26-703-j19-1.2.R |8591832|07:29:00 |07:29:00 |4 |Pfaffhausen, Müseren |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1023 |Bus |74 |\n", "|26-703-j19-1 |8591147 |156.TA.26-703-j19-1.2.R |8591147|07:31:00 |07:31:00 |5 |Zürich, Friedhof Witikon |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1260 |Bus |75 |\n", "|26-703-j19-1 |8591162 |156.TA.26-703-j19-1.2.R |8591162|07:32:00 |07:32:00 |6 |Zürich, Glockenacker |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |146 |Bus |76 |\n", "|26-703-j19-1 |8591261 |156.TA.26-703-j19-1.2.R |8591261|07:33:00 |07:33:00 |7 |Zürich, Loorenstrasse |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1197 |Bus |77 |\n", "|26-703-j19-1 |8591107 |156.TA.26-703-j19-1.2.R |8591107|07:34:00 |07:34:00 |8 |Zürich, Carl-Spitteler-Strasse|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1311 |Bus |78 |\n", "|26-703-j19-1 |8591233 |156.TA.26-703-j19-1.2.R |8591233|07:40:00 |07:40:00 |9 |Zürich, Klusplatz |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9288 |1 |07:25:00 |4 |9 |1133 |Bus |79 |\n", "|26-703-j19-1 |8591825 |144.TA.26-703-j19-1.2.R |8591825|07:27:00 |07:27:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |580 |Bus |80 |\n", "|26-703-j19-1 |8590504 |144.TA.26-703-j19-1.2.R |8590504|07:28:00 |07:28:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |861 |Bus |81 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1366 |Bus |82 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1023 |Bus |83 |\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 |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1260 |Bus |84 |\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 |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |146 |Bus |85 |\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 |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1197 |Bus |86 |\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|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1311 |Bus |87 |\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 |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9231 |1 |07:27:00 |4 |9 |1133 |Bus |88 |\n", "|26-703-j19-1 |8591825 |120.TA.26-703-j19-1.2.R |8591825|07:40:00 |07:40:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |580 |Bus |89 |\n", "|26-703-j19-1 |8590504 |120.TA.26-703-j19-1.2.R |8590504|07:41:00 |07:41:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |861 |Bus |90 |\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 |47.3608915729295|8.623476385787 |Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1366 |Bus |91 |\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 |47.3626987847054|8.61754750491098|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1023 |Bus |92 |\n", "|26-703-j19-1 |8591147 |120.TA.26-703-j19-1.2.R |8591147|07:46:00 |07:46:00 |5 |Zürich, Friedhof Witikon |47.3613418604422|8.60282411740221|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1260 |Bus |93 |\n", "|26-703-j19-1 |8591162 |120.TA.26-703-j19-1.2.R |8591162|07:47:00 |07:47:00 |6 |Zürich, Glockenacker |47.3609767627537|8.59930272148798|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |146 |Bus |94 |\n", "|26-703-j19-1 |8591261 |120.TA.26-703-j19-1.2.R |8591261|07:48:00 |07:48:00 |7 |Zürich, Loorenstrasse |47.3598631991991|8.59452368417579|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1197 |Bus |95 |\n", "|26-703-j19-1 |8591107 |120.TA.26-703-j19-1.2.R |8591107|07:49:00 |07:49:00 |8 |Zürich, Carl-Spitteler-Strasse|47.3583236436636|8.58659156021591|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1311 |Bus |96 |\n", "|26-703-j19-1 |8591233 |120.TA.26-703-j19-1.2.R |8591233|07:55:00 |07:55:00 |9 |Zürich, Klusplatz |47.3640374201824|8.56649624730736|Zürich, Klusplatz |9159 |1 |07:40:00 |4 |9 |1133 |Bus |97 |\n", "|26-703-j19-1 |8591825 |95.TA.26-703-j19-1.2.R |8591825|07:42:00 |07:42:00 |1 |Benglen, Bodenacher |47.3611288870976|8.63861299832652|Zürich, Klusplatz |9119 |1 |07:42:00 |4 |9 |580 |Bus |98 |\n", "|26-703-j19-1 |8590504 |95.TA.26-703-j19-1.2.R |8590504|07:43:00 |07:43:00 |2 |Benglen, Gerlisbrunnen |47.3610862923255|8.63360938219328|Zürich, Klusplatz |9119 |1 |07:42:00 |4 |9 |861 |Bus |99 |\n", "+-------------+---------------+------------------------+-------+------------+--------------+-------------+------------------------------+----------------+----------------+---------------------------+---------------+------------+--------------------+---------+----------+--------+----------+---------------------------+\n", "only showing top 100 rows" ] } ], "source": [ "from pyspark.sql.types import LongType\n", "stop_times = spark.read.csv('data/lgpt_guys/stop_times_final_cyril.csv', header=True)\n", "stop_times = stop_times.sort(stop_times.monotonically_increasing_id.cast(LongType()))\n", "\n", "stop_times.show(100, 0)" ] }, { "cell_type": "code", "execution_count": 123, "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 |stop_lat |stop_lon |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|monotonically_increasing_id|\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 |47.4542439013472|8.63462447846447|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |1200 |Bus |532575945867 |\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) |47.4577182388675|8.63876571192484|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |646 |Bus |532575945868 |\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 |47.4641014319557|8.63995148810004|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |865 |Bus |532575945869 |\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|47.461927224864 |8.66128647610085|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |45 |Bus |532575945870 |\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 |47.470969635094 |8.67059302244562|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |94 |Bus |532575945871 |\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 |47.472038346399 |8.67648597071027|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |1060 |Bus |532575945872 |\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 |47.4714675601105|8.68249569996186|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |778 |Bus |532575945873 |\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 |47.469621570521 |8.68646625351823|Winterthur, Archstrasse/HB|2268 |1 |07:16:00 |500 |8 |1128 |Bus |532575945874 |\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": 126, "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 |stop_lat |stop_lon |trip_headsign |trip_short_name|direction_id|departure_first_stop|route_int|stop_count|stop_int|route_desc|monotonically_increasing_id|\n", "+-----------+---------------+---------------------+-------+------------+--------------+-------------+--------------------------+----------------+----------------+-----------------+---------------+------------+--------------------+---------+----------+--------+----------+---------------------------+\n", "|26-46-j19-1|8591328 |55.TA.26-46-j19-1.3.H|8591328|08:35:00 |08:35:00 |1 |Zürich, Rütihof |47.413451870606 |8.47731150588756|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |881 |Bus |970662609829 |\n", "|26-46-j19-1|8591155 |55.TA.26-46-j19-1.3.H|8591155|08:36:00 |08:36:00 |2 |Zürich, Geeringstrasse |47.4144427264912|8.48043764307674|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |187 |Bus |970662609830 |\n", "|26-46-j19-1|8576241 |55.TA.26-46-j19-1.3.H|8576241|08:38:00 |08:38:00 |3 |Zürich, Heizenholz |47.4122968616864|8.48390514007392|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |57 |Bus |970662609831 |\n", "|26-46-j19-1|8591158 |55.TA.26-46-j19-1.3.H|8591158|08:38:00 |08:38:00 |4 |Zürich, Giblenstrasse |47.4107284405996|8.485953298922 |Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |704 |Bus |970662609832 |\n", "|26-46-j19-1|8591358 |55.TA.26-46-j19-1.3.H|8591358|08:40:00 |08:40:00 |5 |Zürich, Segantinistrasse |47.4074455475966|8.48996876824257|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |1025 |Bus |970662609833 |\n", "|26-46-j19-1|8591371 |55.TA.26-46-j19-1.3.H|8591371|08:40:00 |08:40:00 |6 |Zürich, Singlistrasse |47.4051109214132|8.49349016415681|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |879 |Bus |970662609834 |\n", "|26-46-j19-1|8591431 |55.TA.26-46-j19-1.3.H|8591431|08:41:00 |08:41:00 |7 |Zürich, Wieslergasse |47.4040651698812|8.49596053118848|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |583 |Bus |970662609835 |\n", "|26-46-j19-1|8576240 |55.TA.26-46-j19-1.3.H|8576240|08:43:00 |08:43:00 |8 |Zürich, Meierhofplatz |47.4020100860391|8.49937412926861|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |1221 |Bus |970662609836 |\n", "|26-46-j19-1|8591353 |55.TA.26-46-j19-1.3.H|8591353|08:44:00 |08:44:00 |9 |Zürich, Schwert |47.3997299435837|8.50461130737576|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |816 |Bus |970662609837 |\n", "|26-46-j19-1|8591226 |55.TA.26-46-j19-1.3.H|8591226|08:45:00 |08:45:00 |10 |Zürich, Kempfhofsteig |47.3973037636525|8.51002814853975|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |736 |Bus |970662609838 |\n", "|26-46-j19-1|8591312 |55.TA.26-46-j19-1.3.H|8591312|08:46:00 |08:46:00 |11 |Zürich, Rebbergsteig |47.396902429888 |8.5149688826031 |Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |762 |Bus |970662609839 |\n", "|26-46-j19-1|8591247 |55.TA.26-46-j19-1.3.H|8591247|08:47:00 |08:47:00 |12 |Zürich, Lehenstrasse |47.3962335334876|8.52015216179319|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |1206 |Bus |970662609840 |\n", "|26-46-j19-1|8591323 |55.TA.26-46-j19-1.3.H|8591323|08:48:00 |08:48:00 |13 |Zürich, Rosengartenstrasse|47.394330172729 |8.52546120512307|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |1039 |Bus |970662609841 |\n", "|26-46-j19-1|8580522 |55.TA.26-46-j19-1.3.H|8580522|08:49:00 |08:49:00 |14 |Zürich, Escher-Wyss-Platz |47.3907969150758|8.5223979500038 |Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |455 |Bus |970662609842 |\n", "|26-46-j19-1|8594239 |55.TA.26-46-j19-1.3.H|8594239|08:50:00 |08:50:00 |15 |Zürich, Schiffbau |47.3875735990751|8.51944249271863|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |832 |Bus |970662609843 |\n", "|26-46-j19-1|8591060 |55.TA.26-46-j19-1.3.H|8591060|08:52:00 |08:52:00 |16 |Zürich Hardbrücke, Bahnhof|47.3849339821896|8.51703500775686|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |850 |Bus |970662609844 |\n", "|26-46-j19-1|8591177 |55.TA.26-46-j19-1.3.H|8591177|08:52:00 |08:52:00 |17 |Zürich, Hardplatz |47.3823428932854|8.51452870811382|Zürich, Hardplatz|1106 |0 |08:35:00 |800 |17 |266 |Bus |970662609845 |\n", "|26-46-j19-1|8591328 |54.TA.26-46-j19-1.3.H|8591328|18:35:00 |18:35:00 |1 |Zürich, Rütihof |47.413451870606 |8.47731150588756|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |881 |Bus |970662609846 |\n", "|26-46-j19-1|8591155 |54.TA.26-46-j19-1.3.H|8591155|18:36:00 |18:36:00 |2 |Zürich, Geeringstrasse |47.4144427264912|8.48043764307674|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |187 |Bus |970662609847 |\n", "|26-46-j19-1|8576241 |54.TA.26-46-j19-1.3.H|8576241|18:37:00 |18:37:00 |3 |Zürich, Heizenholz |47.4122968616864|8.48390514007392|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |57 |Bus |970662609848 |\n", "|26-46-j19-1|8591158 |54.TA.26-46-j19-1.3.H|8591158|18:38:00 |18:38:00 |4 |Zürich, Giblenstrasse |47.4107284405996|8.485953298922 |Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |704 |Bus |970662609849 |\n", "|26-46-j19-1|8591358 |54.TA.26-46-j19-1.3.H|8591358|18:39:00 |18:39:00 |5 |Zürich, Segantinistrasse |47.4074455475966|8.48996876824257|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |1025 |Bus |970662609850 |\n", "|26-46-j19-1|8591371 |54.TA.26-46-j19-1.3.H|8591371|18:40:00 |18:40:00 |6 |Zürich, Singlistrasse |47.4051109214132|8.49349016415681|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |879 |Bus |970662609851 |\n", "|26-46-j19-1|8591431 |54.TA.26-46-j19-1.3.H|8591431|18:41:00 |18:41:00 |7 |Zürich, Wieslergasse |47.4040651698812|8.49596053118848|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |583 |Bus |970662609852 |\n", "|26-46-j19-1|8576240 |54.TA.26-46-j19-1.3.H|8576240|18:42:00 |18:42:00 |8 |Zürich, Meierhofplatz |47.4020100860391|8.49937412926861|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |1221 |Bus |970662609853 |\n", "|26-46-j19-1|8591353 |54.TA.26-46-j19-1.3.H|8591353|18:43:00 |18:43:00 |9 |Zürich, Schwert |47.3997299435837|8.50461130737576|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |816 |Bus |970662609854 |\n", "|26-46-j19-1|8591226 |54.TA.26-46-j19-1.3.H|8591226|18:45:00 |18:45:00 |10 |Zürich, Kempfhofsteig |47.3973037636525|8.51002814853975|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |736 |Bus |970662609855 |\n", "|26-46-j19-1|8591312 |54.TA.26-46-j19-1.3.H|8591312|18:45:00 |18:45:00 |11 |Zürich, Rebbergsteig |47.396902429888 |8.5149688826031 |Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |762 |Bus |970662609856 |\n", "|26-46-j19-1|8591247 |54.TA.26-46-j19-1.3.H|8591247|18:47:00 |18:47:00 |12 |Zürich, Lehenstrasse |47.3962335334876|8.52015216179319|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |1206 |Bus |970662609857 |\n", "|26-46-j19-1|8591323 |54.TA.26-46-j19-1.3.H|8591323|18:48:00 |18:48:00 |13 |Zürich, Rosengartenstrasse|47.394330172729 |8.52546120512307|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |1039 |Bus |970662609858 |\n", "|26-46-j19-1|8580522 |54.TA.26-46-j19-1.3.H|8580522|18:49:00 |18:49:00 |14 |Zürich, Escher-Wyss-Platz |47.3907969150758|8.5223979500038 |Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |455 |Bus |970662609859 |\n", "|26-46-j19-1|8594239 |54.TA.26-46-j19-1.3.H|8594239|18:50:00 |18:50:00 |15 |Zürich, Schiffbau |47.3875735990751|8.51944249271863|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |832 |Bus |970662609860 |\n", "|26-46-j19-1|8591060 |54.TA.26-46-j19-1.3.H|8591060|18:51:00 |18:51:00 |16 |Zürich Hardbrücke, Bahnhof|47.3849339821896|8.51703500775686|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |850 |Bus |970662609861 |\n", "|26-46-j19-1|8591177 |54.TA.26-46-j19-1.3.H|8591177|18:52:00 |18:52:00 |17 |Zürich, Hardplatz |47.3823428932854|8.51452870811382|Zürich, Hardplatz|531 |0 |18:35:00 |800 |17 |266 |Bus |970662609862 |\n", "|26-46-j19-1|8591328 |53.TA.26-46-j19-1.3.H|8591328|18:42:00 |18:42:00 |1 |Zürich, Rütihof |47.413451870606 |8.47731150588756|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |881 |Bus |970662609863 |\n", "|26-46-j19-1|8591155 |53.TA.26-46-j19-1.3.H|8591155|18:43:00 |18:43:00 |2 |Zürich, Geeringstrasse |47.4144427264912|8.48043764307674|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |187 |Bus |970662609864 |\n", "|26-46-j19-1|8576241 |53.TA.26-46-j19-1.3.H|8576241|18:45:00 |18:45:00 |3 |Zürich, Heizenholz |47.4122968616864|8.48390514007392|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |57 |Bus |970662609865 |\n", "|26-46-j19-1|8591158 |53.TA.26-46-j19-1.3.H|8591158|18:45:00 |18:45:00 |4 |Zürich, Giblenstrasse |47.4107284405996|8.485953298922 |Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |704 |Bus |970662609866 |\n", "|26-46-j19-1|8591358 |53.TA.26-46-j19-1.3.H|8591358|18:47:00 |18:47:00 |5 |Zürich, Segantinistrasse |47.4074455475966|8.48996876824257|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |1025 |Bus |970662609867 |\n", "|26-46-j19-1|8591371 |53.TA.26-46-j19-1.3.H|8591371|18:47:00 |18:47:00 |6 |Zürich, Singlistrasse |47.4051109214132|8.49349016415681|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |879 |Bus |970662609868 |\n", "|26-46-j19-1|8591431 |53.TA.26-46-j19-1.3.H|8591431|18:48:00 |18:48:00 |7 |Zürich, Wieslergasse |47.4040651698812|8.49596053118848|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |583 |Bus |970662609869 |\n", "|26-46-j19-1|8576240 |53.TA.26-46-j19-1.3.H|8576240|18:50:00 |18:50:00 |8 |Zürich, Meierhofplatz |47.4020100860391|8.49937412926861|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |1221 |Bus |970662609870 |\n", "|26-46-j19-1|8591353 |53.TA.26-46-j19-1.3.H|8591353|18:51:00 |18:51:00 |9 |Zürich, Schwert |47.3997299435837|8.50461130737576|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |816 |Bus |970662609871 |\n", "|26-46-j19-1|8591226 |53.TA.26-46-j19-1.3.H|8591226|18:52:00 |18:52:00 |10 |Zürich, Kempfhofsteig |47.3973037636525|8.51002814853975|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |736 |Bus |970662609872 |\n", "|26-46-j19-1|8591312 |53.TA.26-46-j19-1.3.H|8591312|18:53:00 |18:53:00 |11 |Zürich, Rebbergsteig |47.396902429888 |8.5149688826031 |Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |762 |Bus |970662609873 |\n", "|26-46-j19-1|8591247 |53.TA.26-46-j19-1.3.H|8591247|18:54:00 |18:54:00 |12 |Zürich, Lehenstrasse |47.3962335334876|8.52015216179319|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |1206 |Bus |970662609874 |\n", "|26-46-j19-1|8591323 |53.TA.26-46-j19-1.3.H|8591323|18:55:00 |18:55:00 |13 |Zürich, Rosengartenstrasse|47.394330172729 |8.52546120512307|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |1039 |Bus |970662609875 |\n", "|26-46-j19-1|8580522 |53.TA.26-46-j19-1.3.H|8580522|18:56:00 |18:56:00 |14 |Zürich, Escher-Wyss-Platz |47.3907969150758|8.5223979500038 |Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |455 |Bus |970662609876 |\n", "|26-46-j19-1|8594239 |53.TA.26-46-j19-1.3.H|8594239|18:57:00 |18:57:00 |15 |Zürich, Schiffbau |47.3875735990751|8.51944249271863|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |832 |Bus |970662609877 |\n", "|26-46-j19-1|8591060 |53.TA.26-46-j19-1.3.H|8591060|18:59:00 |18:59:00 |16 |Zürich Hardbrücke, Bahnhof|47.3849339821896|8.51703500775686|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |850 |Bus |970662609878 |\n", "|26-46-j19-1|8591177 |53.TA.26-46-j19-1.3.H|8591177|18:59:00 |18:59:00 |17 |Zürich, Hardplatz |47.3823428932854|8.51452870811382|Zürich, Hardplatz|525 |0 |18:42:00 |800 |17 |266 |Bus |970662609879 |\n", "|26-46-j19-1|8591328 |52.TA.26-46-j19-1.3.H|8591328|18:57:00 |18:57:00 |1 |Zürich, Rütihof |47.413451870606 |8.47731150588756|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |881 |Bus |970662609880 |\n", "|26-46-j19-1|8591155 |52.TA.26-46-j19-1.3.H|8591155|18:58:00 |18:58:00 |2 |Zürich, Geeringstrasse |47.4144427264912|8.48043764307674|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |187 |Bus |970662609881 |\n", "|26-46-j19-1|8576241 |52.TA.26-46-j19-1.3.H|8576241|19:00:00 |19:00:00 |3 |Zürich, Heizenholz |47.4122968616864|8.48390514007392|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |57 |Bus |970662609882 |\n", "|26-46-j19-1|8591158 |52.TA.26-46-j19-1.3.H|8591158|19:00:00 |19:00:00 |4 |Zürich, Giblenstrasse |47.4107284405996|8.485953298922 |Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |704 |Bus |970662609883 |\n", "|26-46-j19-1|8591358 |52.TA.26-46-j19-1.3.H|8591358|19:02:00 |19:02:00 |5 |Zürich, Segantinistrasse |47.4074455475966|8.48996876824257|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |1025 |Bus |970662609884 |\n", "|26-46-j19-1|8591371 |52.TA.26-46-j19-1.3.H|8591371|19:02:00 |19:02:00 |6 |Zürich, Singlistrasse |47.4051109214132|8.49349016415681|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |879 |Bus |970662609885 |\n", "|26-46-j19-1|8591431 |52.TA.26-46-j19-1.3.H|8591431|19:03:00 |19:03:00 |7 |Zürich, Wieslergasse |47.4040651698812|8.49596053118848|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |583 |Bus |970662609886 |\n", "|26-46-j19-1|8576240 |52.TA.26-46-j19-1.3.H|8576240|19:05:00 |19:05:00 |8 |Zürich, Meierhofplatz |47.4020100860391|8.49937412926861|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |1221 |Bus |970662609887 |\n", "|26-46-j19-1|8591353 |52.TA.26-46-j19-1.3.H|8591353|19:06:00 |19:06:00 |9 |Zürich, Schwert |47.3997299435837|8.50461130737576|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |816 |Bus |970662609888 |\n", "|26-46-j19-1|8591226 |52.TA.26-46-j19-1.3.H|8591226|19:07:00 |19:07:00 |10 |Zürich, Kempfhofsteig |47.3973037636525|8.51002814853975|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |736 |Bus |970662609889 |\n", "|26-46-j19-1|8591312 |52.TA.26-46-j19-1.3.H|8591312|19:08:00 |19:08:00 |11 |Zürich, Rebbergsteig |47.396902429888 |8.5149688826031 |Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |762 |Bus |970662609890 |\n", "|26-46-j19-1|8591247 |52.TA.26-46-j19-1.3.H|8591247|19:09:00 |19:09:00 |12 |Zürich, Lehenstrasse |47.3962335334876|8.52015216179319|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |1206 |Bus |970662609891 |\n", "|26-46-j19-1|8591323 |52.TA.26-46-j19-1.3.H|8591323|19:10:00 |19:10:00 |13 |Zürich, Rosengartenstrasse|47.394330172729 |8.52546120512307|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |1039 |Bus |970662609892 |\n", "|26-46-j19-1|8580522 |52.TA.26-46-j19-1.3.H|8580522|19:11:00 |19:11:00 |14 |Zürich, Escher-Wyss-Platz |47.3907969150758|8.5223979500038 |Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |455 |Bus |970662609893 |\n", "|26-46-j19-1|8594239 |52.TA.26-46-j19-1.3.H|8594239|19:12:00 |19:12:00 |15 |Zürich, Schiffbau |47.3875735990751|8.51944249271863|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |832 |Bus |970662609894 |\n", "|26-46-j19-1|8591060 |52.TA.26-46-j19-1.3.H|8591060|19:14:00 |19:14:00 |16 |Zürich Hardbrücke, Bahnhof|47.3849339821896|8.51703500775686|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |850 |Bus |970662609895 |\n", "|26-46-j19-1|8591177 |52.TA.26-46-j19-1.3.H|8591177|19:14:00 |19:14:00 |17 |Zürich, Hardplatz |47.3823428932854|8.51452870811382|Zürich, Hardplatz|514 |0 |18:57:00 |800 |17 |266 |Bus |970662609896 |\n", "|26-46-j19-1|8591328 |51.TA.26-46-j19-1.3.H|8591328|19:05:00 |19:05:00 |1 |Zürich, Rütihof |47.413451870606 |8.47731150588756|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |881 |Bus |970662609897 |\n", "|26-46-j19-1|8591155 |51.TA.26-46-j19-1.3.H|8591155|19:06:00 |19:06:00 |2 |Zürich, Geeringstrasse |47.4144427264912|8.48043764307674|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |187 |Bus |970662609898 |\n", "|26-46-j19-1|8576241 |51.TA.26-46-j19-1.3.H|8576241|19:07:00 |19:07:00 |3 |Zürich, Heizenholz |47.4122968616864|8.48390514007392|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |57 |Bus |970662609899 |\n", "|26-46-j19-1|8591158 |51.TA.26-46-j19-1.3.H|8591158|19:08:00 |19:08:00 |4 |Zürich, Giblenstrasse |47.4107284405996|8.485953298922 |Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |704 |Bus |970662609900 |\n", "|26-46-j19-1|8591358 |51.TA.26-46-j19-1.3.H|8591358|19:09:00 |19:09:00 |5 |Zürich, Segantinistrasse |47.4074455475966|8.48996876824257|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |1025 |Bus |970662609901 |\n", "|26-46-j19-1|8591371 |51.TA.26-46-j19-1.3.H|8591371|19:10:00 |19:10:00 |6 |Zürich, Singlistrasse |47.4051109214132|8.49349016415681|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |879 |Bus |970662609902 |\n", "|26-46-j19-1|8591431 |51.TA.26-46-j19-1.3.H|8591431|19:11:00 |19:11:00 |7 |Zürich, Wieslergasse |47.4040651698812|8.49596053118848|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |583 |Bus |970662609903 |\n", "|26-46-j19-1|8576240 |51.TA.26-46-j19-1.3.H|8576240|19:12:00 |19:12:00 |8 |Zürich, Meierhofplatz |47.4020100860391|8.49937412926861|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |1221 |Bus |970662609904 |\n", "|26-46-j19-1|8591353 |51.TA.26-46-j19-1.3.H|8591353|19:13:00 |19:13:00 |9 |Zürich, Schwert |47.3997299435837|8.50461130737576|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |816 |Bus |970662609905 |\n", "|26-46-j19-1|8591226 |51.TA.26-46-j19-1.3.H|8591226|19:15:00 |19:15:00 |10 |Zürich, Kempfhofsteig |47.3973037636525|8.51002814853975|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |736 |Bus |970662609906 |\n", "|26-46-j19-1|8591312 |51.TA.26-46-j19-1.3.H|8591312|19:15:00 |19:15:00 |11 |Zürich, Rebbergsteig |47.396902429888 |8.5149688826031 |Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |762 |Bus |970662609907 |\n", "|26-46-j19-1|8591247 |51.TA.26-46-j19-1.3.H|8591247|19:17:00 |19:17:00 |12 |Zürich, Lehenstrasse |47.3962335334876|8.52015216179319|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |1206 |Bus |970662609908 |\n", "|26-46-j19-1|8591323 |51.TA.26-46-j19-1.3.H|8591323|19:18:00 |19:18:00 |13 |Zürich, Rosengartenstrasse|47.394330172729 |8.52546120512307|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |1039 |Bus |970662609909 |\n", "|26-46-j19-1|8580522 |51.TA.26-46-j19-1.3.H|8580522|19:19:00 |19:19:00 |14 |Zürich, Escher-Wyss-Platz |47.3907969150758|8.5223979500038 |Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |455 |Bus |970662609910 |\n", "|26-46-j19-1|8594239 |51.TA.26-46-j19-1.3.H|8594239|19:20:00 |19:20:00 |15 |Zürich, Schiffbau |47.3875735990751|8.51944249271863|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |832 |Bus |970662609911 |\n", "|26-46-j19-1|8591060 |51.TA.26-46-j19-1.3.H|8591060|19:21:00 |19:21:00 |16 |Zürich Hardbrücke, Bahnhof|47.3849339821896|8.51703500775686|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |850 |Bus |970662609912 |\n", "|26-46-j19-1|8591177 |51.TA.26-46-j19-1.3.H|8591177|19:22:00 |19:22:00 |17 |Zürich, Hardplatz |47.3823428932854|8.51452870811382|Zürich, Hardplatz|506 |0 |19:05:00 |800 |17 |266 |Bus |970662609913 |\n", "+-----------+---------------+---------------------+-------+------------+--------------+-------------+--------------------------+----------------+----------------+-----------------+---------------+------------+--------------------+---------+----------+--------+----------+---------------------------+" ] } ], "source": [ "stop_times.where(stop_times.route_int==800).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." ] } ], "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 }