Last active
March 27, 2018 19:35
-
-
Save d-wasserman/ead87a0a33af4def670e789522d054f5 to your computer and use it in GitHub Desktop.
Project: Summarize 1 Month of 2017 Citibike OD Data into a a format accepted by Spatial Sankey (geojson for ODs, and flow csv). Uses Google Datalab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Project: Summarize 1 Month of 2017 Citibike OD Data into a format accepted by Spatial Sankey\n", | |
"\n", | |
"Description: Utilizes Geopandas and Pandas to collapse OD pairs and tabulate associated counts based on trip demographics. \n", | |
"\n", | |
"Libraries: Geopandas, Pandas" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import geopandas as gpd\n", | |
"import pandas as pd\n", | |
"import matplotlib.pyplot as plt\n", | |
"import matplotlib.style as mstyle\n", | |
"from shapely.geometry import Point\n", | |
"import datetime\n", | |
"import os\n", | |
"import google.datalab.storage as storage\n", | |
"from google.datalab import Context\n", | |
"from cStringIO import StringIO\n", | |
"from io import BytesIO\n", | |
"mstyle.use(\"ggplot\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Set Up Data\n", | |
"1. Get data from GCloud Storage\n", | |
"2. Generate and describe resulting dataframe" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%gcs read --object gs://dataanalysisengine/data/201706-citibike-tripdata.csv --variable citibikecsv" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>tripduration</th>\n", | |
" <th>start station id</th>\n", | |
" <th>start station latitude</th>\n", | |
" <th>start station longitude</th>\n", | |
" <th>end station id</th>\n", | |
" <th>end station latitude</th>\n", | |
" <th>end station longitude</th>\n", | |
" <th>bikeid</th>\n", | |
" <th>birth year</th>\n", | |
" <th>gender</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>count</th>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" <td>1.539162e+06</td>\n", | |
" <td>1.731594e+06</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>mean</th>\n", | |
" <td>1.072827e+03</td>\n", | |
" <td>1.337900e+03</td>\n", | |
" <td>4.073594e+01</td>\n", | |
" <td>-7.398515e+01</td>\n", | |
" <td>1.333843e+03</td>\n", | |
" <td>4.073566e+01</td>\n", | |
" <td>-7.398523e+01</td>\n", | |
" <td>2.289554e+04</td>\n", | |
" <td>1.978886e+03</td>\n", | |
" <td>1.117142e+00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>std</th>\n", | |
" <td>1.494990e+04</td>\n", | |
" <td>1.337752e+03</td>\n", | |
" <td>5.204005e-02</td>\n", | |
" <td>8.134120e-02</td>\n", | |
" <td>1.336874e+03</td>\n", | |
" <td>6.051320e-02</td>\n", | |
" <td>9.888581e-02</td>\n", | |
" <td>4.916619e+03</td>\n", | |
" <td>1.164359e+01</td>\n", | |
" <td>5.767023e-01</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>min</th>\n", | |
" <td>6.100000e+01</td>\n", | |
" <td>7.200000e+01</td>\n", | |
" <td>0.000000e+00</td>\n", | |
" <td>-7.401713e+01</td>\n", | |
" <td>7.200000e+01</td>\n", | |
" <td>0.000000e+00</td>\n", | |
" <td>-7.404773e+01</td>\n", | |
" <td>1.452900e+04</td>\n", | |
" <td>1.885000e+03</td>\n", | |
" <td>0.000000e+00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>25%</th>\n", | |
" <td>3.910000e+02</td>\n", | |
" <td>3.580000e+02</td>\n", | |
" <td>4.071755e+01</td>\n", | |
" <td>-7.399724e+01</td>\n", | |
" <td>3.580000e+02</td>\n", | |
" <td>4.071755e+01</td>\n", | |
" <td>-7.399725e+01</td>\n", | |
" <td>1.822800e+04</td>\n", | |
" <td>1.971000e+03</td>\n", | |
" <td>1.000000e+00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>50%</th>\n", | |
" <td>6.610000e+02</td>\n", | |
" <td>4.840000e+02</td>\n", | |
" <td>4.073705e+01</td>\n", | |
" <td>-7.398771e+01</td>\n", | |
" <td>4.830000e+02</td>\n", | |
" <td>4.073650e+01</td>\n", | |
" <td>-7.398783e+01</td>\n", | |
" <td>2.497000e+04</td>\n", | |
" <td>1.982000e+03</td>\n", | |
" <td>1.000000e+00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>75%</th>\n", | |
" <td>1.146000e+03</td>\n", | |
" <td>3.137000e+03</td>\n", | |
" <td>4.075514e+01</td>\n", | |
" <td>-7.397621e+01</td>\n", | |
" <td>3.137000e+03</td>\n", | |
" <td>4.075510e+01</td>\n", | |
" <td>-7.397621e+01</td>\n", | |
" <td>2.755400e+04</td>\n", | |
" <td>1.988000e+03</td>\n", | |
" <td>1.000000e+00</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>max</th>\n", | |
" <td>4.182314e+06</td>\n", | |
" <td>3.474000e+03</td>\n", | |
" <td>4.088092e+01</td>\n", | |
" <td>0.000000e+00</td>\n", | |
" <td>3.474000e+03</td>\n", | |
" <td>4.088092e+01</td>\n", | |
" <td>0.000000e+00</td>\n", | |
" <td>2.983400e+04</td>\n", | |
" <td>2.001000e+03</td>\n", | |
" <td>2.000000e+00</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" tripduration start station id start station latitude \\\n", | |
"count 1.731594e+06 1.731594e+06 1.731594e+06 \n", | |
"mean 1.072827e+03 1.337900e+03 4.073594e+01 \n", | |
"std 1.494990e+04 1.337752e+03 5.204005e-02 \n", | |
"min 6.100000e+01 7.200000e+01 0.000000e+00 \n", | |
"25% 3.910000e+02 3.580000e+02 4.071755e+01 \n", | |
"50% 6.610000e+02 4.840000e+02 4.073705e+01 \n", | |
"75% 1.146000e+03 3.137000e+03 4.075514e+01 \n", | |
"max 4.182314e+06 3.474000e+03 4.088092e+01 \n", | |
"\n", | |
" start station longitude end station id end station latitude \\\n", | |
"count 1.731594e+06 1.731594e+06 1.731594e+06 \n", | |
"mean -7.398515e+01 1.333843e+03 4.073566e+01 \n", | |
"std 8.134120e-02 1.336874e+03 6.051320e-02 \n", | |
"min -7.401713e+01 7.200000e+01 0.000000e+00 \n", | |
"25% -7.399724e+01 3.580000e+02 4.071755e+01 \n", | |
"50% -7.398771e+01 4.830000e+02 4.073650e+01 \n", | |
"75% -7.397621e+01 3.137000e+03 4.075510e+01 \n", | |
"max 0.000000e+00 3.474000e+03 4.088092e+01 \n", | |
"\n", | |
" end station longitude bikeid birth year gender \n", | |
"count 1.731594e+06 1.731594e+06 1.539162e+06 1.731594e+06 \n", | |
"mean -7.398523e+01 2.289554e+04 1.978886e+03 1.117142e+00 \n", | |
"std 9.888581e-02 4.916619e+03 1.164359e+01 5.767023e-01 \n", | |
"min -7.404773e+01 1.452900e+04 1.885000e+03 0.000000e+00 \n", | |
"25% -7.399725e+01 1.822800e+04 1.971000e+03 1.000000e+00 \n", | |
"50% -7.398783e+01 2.497000e+04 1.982000e+03 1.000000e+00 \n", | |
"75% -7.397621e+01 2.755400e+04 1.988000e+03 1.000000e+00 \n", | |
"max 0.000000e+00 2.983400e+04 2.001000e+03 2.000000e+00 " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"top_level_out_dir= r\"/content/datalab/data/Output\"\n", | |
"data_dir= r\"/content/datalab/data\"\n", | |
"output_dir = os.path.join(top_level_out_dir,\"SpatialSankey\")\n", | |
"if not os.path.exists(output_dir):\n", | |
" os.makedirs(output_dir)\n", | |
"now = datetime.datetime.now()\n", | |
"citibike_csv= StringIO(citibikecsv)\n", | |
"df = pd.read_csv(citibike_csv,parse_dates=[\"starttime\",\"stoptime\"])\n", | |
"display(df.describe())\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Worker Functions\n", | |
"def get_time_period(Hour,period_dictionary={\"6 AM to 9 AM\":(6,9),\"9 AM to 2 PM\":(9,14),\"2 PM to 4 PM\":(14,16),\"4 PM to 7 PM\":(16,19),\"7 PM to 10 PM\":(19,22),\"10 PM to 1 AM\":(22,1),\"1 AM to 6 AM\":(1,6)}):\n", | |
" Hour = int(Hour)\n", | |
" time_period=None\n", | |
" for period in period_dictionary:\n", | |
" time_tuple=period_dictionary[period]\n", | |
" if time_tuple[0]>time_tuple[1]: #Maxes at 24 hours, if first number is greater reset\n", | |
" if Hour>= time_tuple[0] or Hour < time_tuple[1]:\n", | |
" time_period=period\n", | |
" else:\n", | |
" if Hour>= time_tuple[0] and Hour < time_tuple[1]:\n", | |
" time_period=period\n", | |
" return time_period" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Prepare OD Data for Summary" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>0 to 5 Minutes</th>\n", | |
" <th>5 to 10 Minutes</th>\n", | |
" <th>10 to 15 Minutes</th>\n", | |
" <th>15 to 20 Minutes</th>\n", | |
" <th>Greater than 20 Minutes</th>\n", | |
" <th>Female</th>\n", | |
" <th>Male</th>\n", | |
" <th>1 AM to 6 AM</th>\n", | |
" <th>10 PM to 1 AM</th>\n", | |
" <th>2 PM to 4 PM</th>\n", | |
" <th>...</th>\n", | |
" <th>9 AM to 2 PM</th>\n", | |
" <th>0 to 10 Years Old</th>\n", | |
" <th>10 to 20 Years Old</th>\n", | |
" <th>20 to 30 Years Old</th>\n", | |
" <th>30 to 40 Years Old</th>\n", | |
" <th>40 to 50 Years Old</th>\n", | |
" <th>50 to 60 Years Old</th>\n", | |
" <th>60 to 70 Years Old</th>\n", | |
" <th>70 to 80 Years Old</th>\n", | |
" <th>Greater than 80 Years Old</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>...</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>...</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>...</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>...</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>...</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>5 rows × 23 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 0 to 5 Minutes 5 to 10 Minutes 10 to 15 Minutes 15 to 20 Minutes \\\n", | |
"0 0 0 0 0 \n", | |
"1 0 0 0 1 \n", | |
"2 0 0 0 0 \n", | |
"3 0 0 0 0 \n", | |
"4 0 0 0 0 \n", | |
"\n", | |
" Greater than 20 Minutes Female Male 1 AM to 6 AM 10 PM to 1 AM \\\n", | |
"0 1 0 1 0 1 \n", | |
"1 0 0 1 0 1 \n", | |
"2 1 0 1 0 1 \n", | |
"3 1 1 0 0 1 \n", | |
"4 1 0 1 0 1 \n", | |
"\n", | |
" 2 PM to 4 PM ... 9 AM to 2 PM 0 to 10 Years Old \\\n", | |
"0 0 ... 0 0 \n", | |
"1 0 ... 0 0 \n", | |
"2 0 ... 0 0 \n", | |
"3 0 ... 0 0 \n", | |
"4 0 ... 0 0 \n", | |
"\n", | |
" 10 to 20 Years Old 20 to 30 Years Old 30 to 40 Years Old \\\n", | |
"0 0 0 0 \n", | |
"1 0 0 1 \n", | |
"2 0 0 1 \n", | |
"3 0 0 0 \n", | |
"4 0 0 1 \n", | |
"\n", | |
" 40 to 50 Years Old 50 to 60 Years Old 60 to 70 Years Old \\\n", | |
"0 1 0 0 \n", | |
"1 0 0 0 \n", | |
"2 0 0 0 \n", | |
"3 1 0 0 \n", | |
"4 0 0 0 \n", | |
"\n", | |
" 70 to 80 Years Old Greater than 80 Years Old \n", | |
"0 0 0 \n", | |
"1 0 0 \n", | |
"2 0 0 \n", | |
"3 0 0 \n", | |
"4 0 0 \n", | |
"\n", | |
"[5 rows x 23 columns]" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"df[\"Start Hour\"]=df[\"starttime\"].dt.hour\n", | |
"df[\"T Period\"]=df[\"Start Hour\"].apply(lambda x: get_time_period(x))\n", | |
"df[\"Age\"]= now.year- df[\"birth year\"]\n", | |
"df[\"Age Group\"]= pd.cut(df[\"Age\"],range(0,90,10)+[200],labels=[\"{0} to {1} Years Old\".format(i,j) for i,j in zip(range(0,80,10),range(10,90,10))]+[\"Greater than 80 Years Old\"])\n", | |
"df[\"Duration Group\"] = pd.cut(df[\"tripduration\"],range(0,1500,300)+[1000000],labels=[\"{0} to {1} Minutes\".format(i,j) for i,j in zip(range(0,20,5),range(5,25,5))]+[\"Greater than 20 Minutes\"])\n", | |
"df[\"gender class\"]= df[\"gender\"].apply(lambda x: \"Male\" if x==1 else \"Female\")\n", | |
"df[\"flow\"]=1\n", | |
"df_dummy=pd.get_dummies(df[[\"Duration Group\", \"gender class\",\"T Period\",\"Age Group\"]],prefix=\"\",prefix_sep=\"\")\n", | |
"df_dummy_cols=df_dummy.columns\n", | |
"display(df_dummy.head())\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"('There are ', 4.142857142857143, ' weeks in the dataset.')\n" | |
] | |
} | |
], | |
"source": [ | |
"week_range = (df[\"starttime\"].max()-df[\"starttime\"].min()).days/7.0\n", | |
"print(\"There are \",week_range,\" weeks in the dataset.\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>flow</th>\n", | |
" <th>0 to 5 Minutes</th>\n", | |
" <th>5 to 10 Minutes</th>\n", | |
" <th>10 to 15 Minutes</th>\n", | |
" <th>15 to 20 Minutes</th>\n", | |
" <th>Greater than 20 Minutes</th>\n", | |
" <th>Female</th>\n", | |
" <th>Male</th>\n", | |
" <th>1 AM to 6 AM</th>\n", | |
" <th>10 PM to 1 AM</th>\n", | |
" <th>...</th>\n", | |
" <th>9 AM to 2 PM</th>\n", | |
" <th>0 to 10 Years Old</th>\n", | |
" <th>10 to 20 Years Old</th>\n", | |
" <th>20 to 30 Years Old</th>\n", | |
" <th>30 to 40 Years Old</th>\n", | |
" <th>40 to 50 Years Old</th>\n", | |
" <th>50 to 60 Years Old</th>\n", | |
" <th>60 to 70 Years Old</th>\n", | |
" <th>70 to 80 Years Old</th>\n", | |
" <th>Greater than 80 Years Old</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>count</th>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>...</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.0</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" <td>159088.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>mean</th>\n", | |
" <td>2.505286</td>\n", | |
" <td>0.393197</td>\n", | |
" <td>0.759466</td>\n", | |
" <td>0.453937</td>\n", | |
" <td>0.244921</td>\n", | |
" <td>0.461518</td>\n", | |
" <td>0.804002</td>\n", | |
" <td>1.598134</td>\n", | |
" <td>0.021956</td>\n", | |
" <td>0.081282</td>\n", | |
" <td>...</td>\n", | |
" <td>0.579440</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.013320</td>\n", | |
" <td>0.602629</td>\n", | |
" <td>0.645712</td>\n", | |
" <td>0.366690</td>\n", | |
" <td>0.227534</td>\n", | |
" <td>0.055510</td>\n", | |
" <td>0.003960</td>\n", | |
" <td>0.000666</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>std</th>\n", | |
" <td>5.251572</td>\n", | |
" <td>2.298957</td>\n", | |
" <td>2.635154</td>\n", | |
" <td>1.278561</td>\n", | |
" <td>0.795284</td>\n", | |
" <td>1.693296</td>\n", | |
" <td>2.337181</td>\n", | |
" <td>3.531003</td>\n", | |
" <td>0.212212</td>\n", | |
" <td>0.372497</td>\n", | |
" <td>...</td>\n", | |
" <td>1.624712</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.151943</td>\n", | |
" <td>1.530073</td>\n", | |
" <td>1.637176</td>\n", | |
" <td>1.125984</td>\n", | |
" <td>0.812428</td>\n", | |
" <td>0.334166</td>\n", | |
" <td>0.082756</td>\n", | |
" <td>0.035450</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>min</th>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>...</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>25%</th>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>...</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>50%</th>\n", | |
" <td>1.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>...</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>75%</th>\n", | |
" <td>3.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>1.000000</td>\n", | |
" <td>1.000000</td>\n", | |
" <td>2.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>...</td>\n", | |
" <td>1.000000</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>1.000000</td>\n", | |
" <td>1.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" <td>0.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>max</th>\n", | |
" <td>191.000000</td>\n", | |
" <td>154.000000</td>\n", | |
" <td>100.000000</td>\n", | |
" <td>55.000000</td>\n", | |
" <td>56.000000</td>\n", | |
" <td>146.000000</td>\n", | |
" <td>152.000000</td>\n", | |
" <td>131.000000</td>\n", | |
" <td>16.000000</td>\n", | |
" <td>18.000000</td>\n", | |
" <td>...</td>\n", | |
" <td>93.000000</td>\n", | |
" <td>0.0</td>\n", | |
" <td>13.000000</td>\n", | |
" <td>91.000000</td>\n", | |
" <td>54.000000</td>\n", | |
" <td>31.000000</td>\n", | |
" <td>33.000000</td>\n", | |
" <td>13.000000</td>\n", | |
" <td>5.000000</td>\n", | |
" <td>5.000000</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>8 rows × 24 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" flow 0 to 5 Minutes 5 to 10 Minutes 10 to 15 Minutes \\\n", | |
"count 159088.000000 159088.000000 159088.000000 159088.000000 \n", | |
"mean 2.505286 0.393197 0.759466 0.453937 \n", | |
"std 5.251572 2.298957 2.635154 1.278561 \n", | |
"min 0.000000 0.000000 0.000000 0.000000 \n", | |
"25% 0.000000 0.000000 0.000000 0.000000 \n", | |
"50% 1.000000 0.000000 0.000000 0.000000 \n", | |
"75% 3.000000 0.000000 0.000000 0.000000 \n", | |
"max 191.000000 154.000000 100.000000 55.000000 \n", | |
"\n", | |
" 15 to 20 Minutes Greater than 20 Minutes Female \\\n", | |
"count 159088.000000 159088.000000 159088.000000 \n", | |
"mean 0.244921 0.461518 0.804002 \n", | |
"std 0.795284 1.693296 2.337181 \n", | |
"min 0.000000 0.000000 0.000000 \n", | |
"25% 0.000000 0.000000 0.000000 \n", | |
"50% 0.000000 0.000000 0.000000 \n", | |
"75% 0.000000 1.000000 1.000000 \n", | |
"max 56.000000 146.000000 152.000000 \n", | |
"\n", | |
" Male 1 AM to 6 AM 10 PM to 1 AM ... \\\n", | |
"count 159088.000000 159088.000000 159088.000000 ... \n", | |
"mean 1.598134 0.021956 0.081282 ... \n", | |
"std 3.531003 0.212212 0.372497 ... \n", | |
"min 0.000000 0.000000 0.000000 ... \n", | |
"25% 0.000000 0.000000 0.000000 ... \n", | |
"50% 0.000000 0.000000 0.000000 ... \n", | |
"75% 2.000000 0.000000 0.000000 ... \n", | |
"max 131.000000 16.000000 18.000000 ... \n", | |
"\n", | |
" 9 AM to 2 PM 0 to 10 Years Old 10 to 20 Years Old \\\n", | |
"count 159088.000000 159088.0 159088.000000 \n", | |
"mean 0.579440 0.0 0.013320 \n", | |
"std 1.624712 0.0 0.151943 \n", | |
"min 0.000000 0.0 0.000000 \n", | |
"25% 0.000000 0.0 0.000000 \n", | |
"50% 0.000000 0.0 0.000000 \n", | |
"75% 1.000000 0.0 0.000000 \n", | |
"max 93.000000 0.0 13.000000 \n", | |
"\n", | |
" 20 to 30 Years Old 30 to 40 Years Old 40 to 50 Years Old \\\n", | |
"count 159088.000000 159088.000000 159088.000000 \n", | |
"mean 0.602629 0.645712 0.366690 \n", | |
"std 1.530073 1.637176 1.125984 \n", | |
"min 0.000000 0.000000 0.000000 \n", | |
"25% 0.000000 0.000000 0.000000 \n", | |
"50% 0.000000 0.000000 0.000000 \n", | |
"75% 1.000000 1.000000 0.000000 \n", | |
"max 91.000000 54.000000 31.000000 \n", | |
"\n", | |
" 50 to 60 Years Old 60 to 70 Years Old 70 to 80 Years Old \\\n", | |
"count 159088.000000 159088.000000 159088.000000 \n", | |
"mean 0.227534 0.055510 0.003960 \n", | |
"std 0.812428 0.334166 0.082756 \n", | |
"min 0.000000 0.000000 0.000000 \n", | |
"25% 0.000000 0.000000 0.000000 \n", | |
"50% 0.000000 0.000000 0.000000 \n", | |
"75% 0.000000 0.000000 0.000000 \n", | |
"max 33.000000 13.000000 5.000000 \n", | |
"\n", | |
" Greater than 80 Years Old \n", | |
"count 159088.000000 \n", | |
"mean 0.000666 \n", | |
"std 0.035450 \n", | |
"min 0.000000 \n", | |
"25% 0.000000 \n", | |
"50% 0.000000 \n", | |
"75% 0.000000 \n", | |
"max 5.000000 \n", | |
"\n", | |
"[8 rows x 24 columns]" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"df_agg= pd.merge(df, df_dummy,right_index=True,left_index=True)\n", | |
"odgroups=df_agg.groupby(by=[\"start station id\",\"end station id\",\"start station latitude\",\"start station longitude\",\"end station latitude\",\"end station longitude\"])\n", | |
"odgroupstats=odgroups[[\"flow\"]+list(df_dummy_cols)].agg(\"sum\")\n", | |
"odgroupstats=(odgroupstats/week_range).round(0) #Get Trips Per Week\n", | |
"display(odgroupstats.describe())" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Generate Outputs\n", | |
"Generate outputs looked for by spatial sankey- OD Table with flows and geojson file. \n", | |
"An additional version of the OD table with the summarized data is also created. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>source</th>\n", | |
" <th>target</th>\n", | |
" <th>start station latitude</th>\n", | |
" <th>start station longitude</th>\n", | |
" <th>end station latitude</th>\n", | |
" <th>end station longitude</th>\n", | |
" <th>flow</th>\n", | |
" <th>0 to 5 Minutes</th>\n", | |
" <th>5 to 10 Minutes</th>\n", | |
" <th>10 to 15 Minutes</th>\n", | |
" <th>...</th>\n", | |
" <th>9 AM to 2 PM</th>\n", | |
" <th>0 to 10 Years Old</th>\n", | |
" <th>10 to 20 Years Old</th>\n", | |
" <th>20 to 30 Years Old</th>\n", | |
" <th>30 to 40 Years Old</th>\n", | |
" <th>40 to 50 Years Old</th>\n", | |
" <th>50 to 60 Years Old</th>\n", | |
" <th>60 to 70 Years Old</th>\n", | |
" <th>70 to 80 Years Old</th>\n", | |
" <th>Greater than 80 Years Old</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>72</td>\n", | |
" <td>72</td>\n", | |
" <td>40.767272</td>\n", | |
" <td>-73.993929</td>\n", | |
" <td>40.767272</td>\n", | |
" <td>-73.993929</td>\n", | |
" <td>31.0</td>\n", | |
" <td>8.0</td>\n", | |
" <td>4.0</td>\n", | |
" <td>2.0</td>\n", | |
" <td>...</td>\n", | |
" <td>7.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>7.0</td>\n", | |
" <td>5.0</td>\n", | |
" <td>3.0</td>\n", | |
" <td>4.0</td>\n", | |
" <td>3.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>72</td>\n", | |
" <td>79</td>\n", | |
" <td>40.767272</td>\n", | |
" <td>-73.993929</td>\n", | |
" <td>40.719116</td>\n", | |
" <td>-74.006667</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>...</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>72</td>\n", | |
" <td>116</td>\n", | |
" <td>40.767272</td>\n", | |
" <td>-73.993929</td>\n", | |
" <td>40.741776</td>\n", | |
" <td>-74.001497</td>\n", | |
" <td>2.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>...</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>72</td>\n", | |
" <td>127</td>\n", | |
" <td>40.767272</td>\n", | |
" <td>-73.993929</td>\n", | |
" <td>40.731724</td>\n", | |
" <td>-74.006744</td>\n", | |
" <td>7.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>...</td>\n", | |
" <td>2.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>1.0</td>\n", | |
" <td>2.0</td>\n", | |
" <td>2.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>72</td>\n", | |
" <td>128</td>\n", | |
" <td>40.767272</td>\n", | |
" <td>-73.993929</td>\n", | |
" <td>40.727103</td>\n", | |
" <td>-74.002971</td>\n", | |
" <td>1.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>...</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>0.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>5 rows × 30 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" source target start station latitude start station longitude \\\n", | |
"0 72 72 40.767272 -73.993929 \n", | |
"1 72 79 40.767272 -73.993929 \n", | |
"2 72 116 40.767272 -73.993929 \n", | |
"3 72 127 40.767272 -73.993929 \n", | |
"4 72 128 40.767272 -73.993929 \n", | |
"\n", | |
" end station latitude end station longitude flow 0 to 5 Minutes \\\n", | |
"0 40.767272 -73.993929 31.0 8.0 \n", | |
"1 40.719116 -74.006667 1.0 0.0 \n", | |
"2 40.741776 -74.001497 2.0 0.0 \n", | |
"3 40.731724 -74.006744 7.0 0.0 \n", | |
"4 40.727103 -74.002971 1.0 0.0 \n", | |
"\n", | |
" 5 to 10 Minutes 10 to 15 Minutes ... 9 AM to 2 PM \\\n", | |
"0 4.0 2.0 ... 7.0 \n", | |
"1 0.0 0.0 ... 0.0 \n", | |
"2 0.0 0.0 ... 0.0 \n", | |
"3 0.0 0.0 ... 2.0 \n", | |
"4 0.0 0.0 ... 0.0 \n", | |
"\n", | |
" 0 to 10 Years Old 10 to 20 Years Old 20 to 30 Years Old \\\n", | |
"0 0.0 0.0 7.0 \n", | |
"1 0.0 0.0 0.0 \n", | |
"2 0.0 0.0 0.0 \n", | |
"3 0.0 0.0 1.0 \n", | |
"4 0.0 0.0 0.0 \n", | |
"\n", | |
" 30 to 40 Years Old 40 to 50 Years Old 50 to 60 Years Old \\\n", | |
"0 5.0 3.0 4.0 \n", | |
"1 1.0 0.0 0.0 \n", | |
"2 1.0 0.0 0.0 \n", | |
"3 2.0 2.0 0.0 \n", | |
"4 0.0 0.0 0.0 \n", | |
"\n", | |
" 60 to 70 Years Old 70 to 80 Years Old Greater than 80 Years Old \n", | |
"0 3.0 0.0 0.0 \n", | |
"1 0.0 0.0 0.0 \n", | |
"2 0.0 0.0 0.0 \n", | |
"3 0.0 0.0 0.0 \n", | |
"4 0.0 0.0 0.0 \n", | |
"\n", | |
"[5 rows x 30 columns]" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"odgroupstats.reset_index(level=odgroupstats.index.names, inplace=True)\n", | |
"odgroupstats=odgroupstats.rename(index=str,columns={\"start station id\":\"source\",\"end station id\":\"target\"})\n", | |
"display(odgroupstats.head())" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Generate OD Flow Tables" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>target</th>\n", | |
" <th>source</th>\n", | |
" <th>flow</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>72</td>\n", | |
" <td>72</td>\n", | |
" <td>31.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>79</td>\n", | |
" <td>72</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>116</td>\n", | |
" <td>72</td>\n", | |
" <td>2.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>127</td>\n", | |
" <td>72</td>\n", | |
" <td>7.0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>128</td>\n", | |
" <td>72</td>\n", | |
" <td>1.0</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" target source flow\n", | |
"0 72 72 31.0\n", | |
"1 79 72 1.0\n", | |
"2 116 72 2.0\n", | |
"3 127 72 7.0\n", | |
"4 128 72 1.0" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"links_out = os.path.join(output_dir,\"links.csv\")\n", | |
"links_out_long = os.path.join(output_dir,\"links_long.csv\")\n", | |
"odgroupstats[[\"target\",\"source\",\"flow\"]].to_csv(links_out,index=False)\n", | |
"field_names=odgroupstats.columns\n", | |
"long_name_fields=[str(i) for i in field_names if i not in ['source', 'target', 'start station latitude', 'start station longitude', 'end station latitude', 'end station longitude', 'flow']]\n", | |
"odgroupstats[[\"target\",\"source\",\"flow\"]+long_name_fields].to_csv(links_out_long,index=False)\n", | |
"display(odgroupstats[[\"target\",\"source\",\"flow\"]].head())" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Generate Geojson OD File\n", | |
"Get unique origins and reduce to geojson file with respective ID" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:1320: UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans\n", | |
" (prop.get_family(), self.defaultFamily[fontext]))\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>geometry</th>\n", | |
" <th>id</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>POINT (-73.99392888 40.76727216)</td>\n", | |
" <td>72</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>POINT (-74.00666661 40.71911552)</td>\n", | |
" <td>79</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>POINT (-74.00016545 40.71117416)</td>\n", | |
" <td>82</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>POINT (-73.97632328 40.68382604)</td>\n", | |
" <td>83</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>POINT (-74.00149746 40.74177603)</td>\n", | |
" <td>116</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" geometry id\n", | |
"0 POINT (-73.99392888 40.76727216) 72\n", | |
"1 POINT (-74.00666661 40.71911552) 79\n", | |
"2 POINT (-74.00016545 40.71117416) 82\n", | |
"3 POINT (-73.97632328 40.68382604) 83\n", | |
"4 POINT (-74.00149746 40.74177603) 116" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAM8AAAFKCAYAAAC6iwuAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJztnX90VFWW7z+3qgghIalQgUAnCEkQ\nGPnRgE3bWUYRwWb5HtPT7cy46AfMa21pf7XJII4z4T3aHwiDLQbTCjSgPuM0sx7TPWtNa69hdffr\nYbFobKIkQW1KhCQoCojRKhLKpEKSuuf9UUmRpH7fVCX1Y3/WYoWqe8+95yT3e885++yzt6aUUgiC\nEDWm0a6AICQrIh5BMIiIRxAMIuIRBIOIeATBICIeQTCIiEcQDGIZ7QpEy8WLF0f1/oWFhaNeh1gj\nbQp/rUBELB5d16mqqsJms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AAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x7f65984e78d0>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"odgroupgeo= odgroupstats[[\"source\",\"start station latitude\", \"start station longitude\"]].drop_duplicates()\n", | |
"odgroupgeo= odgroupgeo[(odgroupgeo[\"start station latitude\"]!=0) & (odgroupgeo[\"start station longitude\"]!=0)]\n", | |
"geometry = [Point(xy) for xy in zip(odgroupgeo[\"start station longitude\"],odgroupgeo[\"start station latitude\"])]\n", | |
"\n", | |
"crs = {'init': 'epsg:4326'}\n", | |
"citi_gdf = gpd.GeoDataFrame(odgroupgeo, crs=crs, geometry=geometry)\n", | |
"citi_gdf = citi_gdf[[\"geometry\",\"source\"]].reset_index(drop=True)\n", | |
"citi_gdf = citi_gdf.rename(index=str,columns={\"source\":\"id\"})\n", | |
"citi_gdf.plot()\n", | |
"display(citi_gdf.head())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <script src=\"/static/components/requirejs/require.js\"></script>\n", | |
" <script>\n", | |
" requirejs.config({\n", | |
" paths: {\n", | |
" base: '/static/base',\n", | |
" },\n", | |
" });\n", | |
" </script>\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Saved Geojson File\n" | |
] | |
} | |
], | |
"source": [ | |
"out_geojson= os.path.join(output_dir,\"nodes.geojson\")\n", | |
"if os.path.exists(out_geojson):\n", | |
" os.remove(out_geojson)\n", | |
"citi_gdf.to_file(out_geojson, driver=\"GeoJSON\")\n", | |
"print(\"Saved Geojson File\")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment