Skip to content

Instantly share code, notes, and snippets.

@pilipolio
Created August 24, 2018 09:04
Show Gist options
  • Save pilipolio/7eb7129b033de9e8b15e6007db22b13a to your computer and use it in GitHub Desktop.
Save pilipolio/7eb7129b033de9e8b15e6007db22b13a to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\"Duration\",\"Start date\",\"End date\",\"Start station number\",\"Start station\",\"End station number\",\"End station\",\"Bike number\",\"Member type\"\r\n",
"267,\"2018-07-01 00:00:58\",\"2018-07-01 00:05:26\",31608,\"8th & Eye St SE / Barracks Row\",31610,\"Eastern Market / 7th & North Carolina Ave SE\",\"W23296\",\"Member\"\r\n",
"530,\"2018-07-01 00:01:00\",\"2018-07-01 00:09:50\",31230,\"Metro Center / 12th & G St NW\",31266,\"11th & M St NW\",\"W20838\",\"Member\"\r\n",
"3223,\"2018-07-01 00:01:07\",\"2018-07-01 00:54:50\",31620,\"5th & F St NW\",31289,\"Henry Bacon Dr & Lincoln Memorial Circle NW\",\"W22733\",\"Member\"\r\n",
"2153,\"2018-07-01 00:01:13\",\"2018-07-01 00:37:06\",31258,\"Lincoln Memorial\",31208,\"M St & New Jersey Ave SE\",\"W00196\",\"Casual\"\r\n",
"3214,\"2018-07-01 00:01:13\",\"2018-07-01 00:54:47\",31620,\"5th & F St NW\",31289,\"Henry Bacon Dr & Lincoln Memorial Circle NW\",\"W21070\",\"Member\"\r\n",
"3826,\"2018-07-01 00:01:14\",\"2018-07-01 01:05:00\",31217,\"USDA / 12th & C St SW\",31222,\"New York Ave & 15th St NW\",\"W21845\",\"Casual\"\r\n",
"1585,\"2018-07-01 00:01:16\",\"2018-07-01 00:27:41\",31265,\"5th St & Massachusetts Ave NW\",31520,\"24th & R St NE / National Arboretum\",\"W22025\",\"Member\"\r\n",
"2285,\"2018-07-01 00:01:25\",\"2018-07-01 00:39:30\",31258,\"Lincoln Memorial\",31209,\"1st & N St SE\",\"W22145\",\"Casual\"\r\n",
"742,\"2018-07-01 00:01:45\",\"2018-07-01 00:14:08\",31609,\"Maine Ave & 7th St SW\",31228,\"8th & H St NW\",\"W21379\",\"Member\"\r\n"
]
}
],
"source": [
"! unzip -p /Users/allaingu/Downloads/201807-capitalbikeshare-tripdata.zip 201807-capitalbikeshare-tripdata.csv | head"
]
},
{
"cell_type": "code",
"execution_count": 98,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Duration</th>\n",
" <th>start_time</th>\n",
" <th>end_time</th>\n",
" <th>from_station</th>\n",
" <th>Start station</th>\n",
" <th>to_station</th>\n",
" <th>End station</th>\n",
" <th>Bike number</th>\n",
" <th>Member type</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>267</td>\n",
" <td>2018-07-01 00:00:58</td>\n",
" <td>2018-07-01 00:05:26</td>\n",
" <td>31608</td>\n",
" <td>8th &amp; Eye St SE / Barracks Row</td>\n",
" <td>31610</td>\n",
" <td>Eastern Market / 7th &amp; North Carolina Ave SE</td>\n",
" <td>W23296</td>\n",
" <td>Member</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>530</td>\n",
" <td>2018-07-01 00:01:00</td>\n",
" <td>2018-07-01 00:09:50</td>\n",
" <td>31230</td>\n",
" <td>Metro Center / 12th &amp; G St NW</td>\n",
" <td>31266</td>\n",
" <td>11th &amp; M St NW</td>\n",
" <td>W20838</td>\n",
" <td>Member</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3223</td>\n",
" <td>2018-07-01 00:01:07</td>\n",
" <td>2018-07-01 00:54:50</td>\n",
" <td>31620</td>\n",
" <td>5th &amp; F St NW</td>\n",
" <td>31289</td>\n",
" <td>Henry Bacon Dr &amp; Lincoln Memorial Circle NW</td>\n",
" <td>W22733</td>\n",
" <td>Member</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2153</td>\n",
" <td>2018-07-01 00:01:13</td>\n",
" <td>2018-07-01 00:37:06</td>\n",
" <td>31258</td>\n",
" <td>Lincoln Memorial</td>\n",
" <td>31208</td>\n",
" <td>M St &amp; New Jersey Ave SE</td>\n",
" <td>W00196</td>\n",
" <td>Casual</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>3214</td>\n",
" <td>2018-07-01 00:01:13</td>\n",
" <td>2018-07-01 00:54:47</td>\n",
" <td>31620</td>\n",
" <td>5th &amp; F St NW</td>\n",
" <td>31289</td>\n",
" <td>Henry Bacon Dr &amp; Lincoln Memorial Circle NW</td>\n",
" <td>W21070</td>\n",
" <td>Member</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Duration start_time end_time from_station \\\n",
"0 267 2018-07-01 00:00:58 2018-07-01 00:05:26 31608 \n",
"1 530 2018-07-01 00:01:00 2018-07-01 00:09:50 31230 \n",
"2 3223 2018-07-01 00:01:07 2018-07-01 00:54:50 31620 \n",
"3 2153 2018-07-01 00:01:13 2018-07-01 00:37:06 31258 \n",
"4 3214 2018-07-01 00:01:13 2018-07-01 00:54:47 31620 \n",
"\n",
" Start station to_station \\\n",
"0 8th & Eye St SE / Barracks Row 31610 \n",
"1 Metro Center / 12th & G St NW 31266 \n",
"2 5th & F St NW 31289 \n",
"3 Lincoln Memorial 31208 \n",
"4 5th & F St NW 31289 \n",
"\n",
" End station Bike number Member type \n",
"0 Eastern Market / 7th & North Carolina Ave SE W23296 Member \n",
"1 11th & M St NW W20838 Member \n",
"2 Henry Bacon Dr & Lincoln Memorial Circle NW W22733 Member \n",
"3 M St & New Jersey Ave SE W00196 Casual \n",
"4 Henry Bacon Dr & Lincoln Memorial Circle NW W21070 Member "
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"trip_data = pd.read_csv(\n",
" '/Users/allaingu/Downloads/201807-capitalbikeshare-tripdata.zip',\n",
" parse_dates=['Start date', 'End date'])\\\n",
" .rename(columns={'Start station number': 'from_station', 'End station number': 'to_station', \n",
" 'Start date': 'start_time', 'End date': 'end_time'})\n",
"\n",
"trip_data.head()"
]
},
{
"cell_type": "code",
"execution_count": 103,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>from_station</th>\n",
" <th>Start station</th>\n",
" <th>to_station</th>\n",
" <th>End station</th>\n",
" <th>Bike number</th>\n",
" <th>Member type</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>404761</td>\n",
" <td>404761</td>\n",
" <td>404761</td>\n",
" <td>404761</td>\n",
" <td>404761</td>\n",
" <td>404761</td>\n",
" </tr>\n",
" <tr>\n",
" <th>unique</th>\n",
" <td>506</td>\n",
" <td>506</td>\n",
" <td>506</td>\n",
" <td>506</td>\n",
" <td>4260</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>top</th>\n",
" <td>31258</td>\n",
" <td>Lincoln Memorial</td>\n",
" <td>31258</td>\n",
" <td>Lincoln Memorial</td>\n",
" <td>W22174</td>\n",
" <td>Member</td>\n",
" </tr>\n",
" <tr>\n",
" <th>freq</th>\n",
" <td>8169</td>\n",
" <td>8169</td>\n",
" <td>8223</td>\n",
" <td>8223</td>\n",
" <td>266</td>\n",
" <td>293289</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" from_station Start station to_station End station \\\n",
"count 404761 404761 404761 404761 \n",
"unique 506 506 506 506 \n",
"top 31258 Lincoln Memorial 31258 Lincoln Memorial \n",
"freq 8169 8169 8223 8223 \n",
"\n",
" Bike number Member type \n",
"count 404761 404761 \n",
"unique 4260 2 \n",
"top W22174 Member \n",
"freq 266 293289 "
]
},
"execution_count": 103,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trip_data.astype({'from_station': 'category', 'to_station': 'category', 'Bike number': 'category', 'Member type': 'category'})\\\n",
"[['from_station', 'Start station', 'to_station', 'End station', 'Bike number', 'Member type']].describe()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Duration</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>404761.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>1354.635708</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>2436.873717</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>60.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>450.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>802.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>1401.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>86288.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Duration\n",
"count 404761.000000\n",
"mean 1354.635708\n",
"std 2436.873717\n",
"min 60.000000\n",
"25% 450.000000\n",
"50% 802.000000\n",
"75% 1401.000000\n",
"max 86288.000000"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEMCAYAAAAvaXplAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE/BJREFUeJzt3X2QXfV93/H3x6jGGIzMQ2ZLBY3wwDjBaNLYKqZ1k9mO\n0qLWbmA8GGuCbSmjoElN3DSjTgJJJ2n/oIGZYmrGtTOqcXmwa5BVT6zUxYkHZyfxTAELP4wMlKAa\nMJJ5MA+GyDXYS7794551L/tbae9d7e690r5fM3f2nN85v3N/56t797PnnHuPUlVIktTvNaMegCRp\n/BgOkqSG4SBJahgOkqSG4SBJahgOkqSG4SAtsyR3Jtk86nFIhxO/56CVJMmjwAQwDbwCPADcCuyo\nqr9Zguf7d8A5VfW+xd62tJQ8ctBK9C+q6g3ATwPXAr8D3DTsRpKsWuyBSePCcNCKVVUvVNVu4L3A\n5iTnJ5lK8msz6yTZkuQrffOV5MokDwMPd20fSfJ4kheT3JfkF7r2jcDvAu9NcjDJN7v2nzxHktck\n+bdJHkvydJJbk6zulq3tnm9zku8keSbJ7y1TebTCGQ5a8arqXmA/8AsDdrkEeDtwXjf/VeDvAacC\n/w34bJLXVdUXgf8A3FFVJ1XVz82xrS3d4x8DbwJOAj46a51/BLwZ2AD8fpKfHXCc0oIZDlLPd+n9\nch/EH1bVc1X1Q4Cq+lRVPVtV01V1PXA8vV/m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"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import numpy as np\n",
"\n",
"#trip_data[['Duration']].hist(bins=1000)\n",
"trip_data[['Duration']].hist(bins=np.logspace(1, 5, 20))\n",
"plt.xscale('log')\n",
"trip_data[['Duration']].describe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Stations"
]
},
{
"cell_type": "code",
"execution_count": 104,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(506, 2) (506, 2) (506, 1)\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>station_name</th>\n",
" </tr>\n",
" <tr>\n",
" <th>station_id</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>31608</th>\n",
" <td>8th &amp; Eye St SE / Barracks Row</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31230</th>\n",
" <td>Metro Center / 12th &amp; G St NW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31620</th>\n",
" <td>5th &amp; F St NW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31258</th>\n",
" <td>Lincoln Memorial</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31217</th>\n",
" <td>USDA / 12th &amp; C St SW</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" station_name\n",
"station_id \n",
"31608 8th & Eye St SE / Barracks Row\n",
"31230 Metro Center / 12th & G St NW\n",
"31620 5th & F St NW\n",
"31258 Lincoln Memorial\n",
"31217 USDA / 12th & C St SW"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"start_stations = trip_data[['Start station', 'from_station']]\\\n",
" .drop_duplicates()\\\n",
" .rename(columns={'Start station': 'station_name', 'from_station': 'station_id'})\n",
"\n",
"stop_stations = trip_data[['End station', 'to_station']]\\\n",
" .drop_duplicates()\\\n",
" .rename(columns={'End station': 'station_name', 'to_station': 'station_id'})\n",
"\n",
"stations = pd.concat([start_stations, stop_stations]).drop_duplicates().set_index('station_id')\n",
"print(start_stations.shape, stop_stations.shape, stations.shape)\n",
"\n",
"stations.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Station locations\n",
"\n",
"Annoying to be downloaded from somewhere else http://opendata.dc.gov/datasets/capital-bike-share-locations"
]
},
{
"cell_type": "code",
"execution_count": 105,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>objectid</th>\n",
" <th>id</th>\n",
" <th>address</th>\n",
" <th>terminal_number</th>\n",
" <th>latitude</th>\n",
" <th>longitude</th>\n",
" <th>installed</th>\n",
" <th>locked</th>\n",
" <th>install_date</th>\n",
" <th>removal_date</th>\n",
" <th>temporary_install</th>\n",
" <th>number_of_bikes</th>\n",
" <th>number_of_empty_docks</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" <th>se_anno_cad_data</th>\n",
" <th>owner</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>216255287</td>\n",
" <td>26</td>\n",
" <td>20th &amp; E St NW</td>\n",
" <td>31204</td>\n",
" <td>38.896300</td>\n",
" <td>-77.045000</td>\n",
" <td>YES</td>\n",
" <td>NO</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NO</td>\n",
" <td>2</td>\n",
" <td>13</td>\n",
" <td>396096.323780</td>\n",
" <td>136495.534104</td>\n",
" <td>NaN</td>\n",
" <td>DC</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>216255288</td>\n",
" <td>27</td>\n",
" <td>21st &amp; I St NW</td>\n",
" <td>31205</td>\n",
" <td>38.900800</td>\n",
" <td>-77.047000</td>\n",
" <td>YES</td>\n",
" <td>NO</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NO</td>\n",
" <td>0</td>\n",
" <td>33</td>\n",
" <td>395923.084260</td>\n",
" <td>136995.157405</td>\n",
" <td>NaN</td>\n",
" <td>DC</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>216255289</td>\n",
" <td>91</td>\n",
" <td>13th St &amp; New York Ave NW</td>\n",
" <td>31227</td>\n",
" <td>38.900283</td>\n",
" <td>-77.029822</td>\n",
" <td>YES</td>\n",
" <td>NO</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NO</td>\n",
" <td>2</td>\n",
" <td>21</td>\n",
" <td>397413.134775</td>\n",
" <td>136937.139289</td>\n",
" <td>NaN</td>\n",
" <td>DC</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>216255290</td>\n",
" <td>105</td>\n",
" <td>7th &amp; F St NW / National Portrait Gallery</td>\n",
" <td>31232</td>\n",
" <td>38.897296</td>\n",
" <td>-77.022201</td>\n",
" <td>YES</td>\n",
" <td>NO</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NO</td>\n",
" <td>2</td>\n",
" <td>22</td>\n",
" <td>398074.126479</td>\n",
" <td>136605.370063</td>\n",
" <td>NaN</td>\n",
" <td>DC</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>216255291</td>\n",
" <td>106</td>\n",
" <td>17th &amp; K St NW / Farragut Square</td>\n",
" <td>31233</td>\n",
" <td>38.902061</td>\n",
" <td>-77.038322</td>\n",
" <td>YES</td>\n",
" <td>NO</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NO</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>396675.897757</td>\n",
" <td>137134.786759</td>\n",
" <td>NaN</td>\n",
" <td>DC</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" objectid id address terminal_number \\\n",
"0 216255287 26 20th & E St NW 31204 \n",
"1 216255288 27 21st & I St NW 31205 \n",
"2 216255289 91 13th St & New York Ave NW 31227 \n",
"3 216255290 105 7th & F St NW / National Portrait Gallery 31232 \n",
"4 216255291 106 17th & K St NW / Farragut Square 31233 \n",
"\n",
" latitude longitude installed locked install_date removal_date \\\n",
"0 38.896300 -77.045000 YES NO NaN NaN \n",
"1 38.900800 -77.047000 YES NO NaN NaN \n",
"2 38.900283 -77.029822 YES NO NaN NaN \n",
"3 38.897296 -77.022201 YES NO NaN NaN \n",
"4 38.902061 -77.038322 YES NO NaN NaN \n",
"\n",
" temporary_install number_of_bikes number_of_empty_docks x \\\n",
"0 NO 2 13 396096.323780 \n",
"1 NO 0 33 395923.084260 \n",
"2 NO 2 21 397413.134775 \n",
"3 NO 2 22 398074.126479 \n",
"4 NO 1 33 396675.897757 \n",
"\n",
" y se_anno_cad_data owner \n",
"0 136495.534104 NaN DC \n",
"1 136995.157405 NaN DC \n",
"2 136937.139289 NaN DC \n",
"3 136605.370063 NaN DC \n",
"4 137134.786759 NaN DC "
]
},
"execution_count": 105,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"station_locations = pd.read_csv('/Users/allaingu/Downloads/Capital_Bike_Share_Locations.csv')\n",
"station_locations.columns = [c.lower() for c in station_locations.columns]\n",
"\n",
"station_locations.head()"
]
},
{
"cell_type": "code",
"execution_count": 106,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1085a3c4833e41aaa85d33ea1acc6fb2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(basemap={'url': 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19, 'attribution': 'Map …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ipyleaflet import Map, Marker, MarkerCluster\n",
"\n",
"m = Map(center=(38.9, -77), zoom=10)\n",
"\n",
"marker_cluster = MarkerCluster(\n",
" markers=[Marker(location=(row['latitude'], row['longitude']), title=str(row['terminal_number'])) for _, row in station_locations.iterrows()]\n",
")\n",
"m.add_layer(marker_cluster);\n",
"\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 109,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(508, 17)\n",
"(506, 1)\n",
"(506, 3)\n"
]
}
],
"source": [
"merged_stations = stations.join(\n",
" station_locations.set_index('terminal_number')[['latitude', 'longitude']],\n",
" how='inner'\n",
")\n",
"\n",
"print(station_locations.shape)\n",
"print(stations.shape)\n",
"print(merged_stations.shape)"
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>station_name</th>\n",
" <th>latitude</th>\n",
" <th>longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>31608</th>\n",
" <td>8th &amp; Eye St SE / Barracks Row</td>\n",
" <td>38.879200</td>\n",
" <td>-76.995300</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31230</th>\n",
" <td>Metro Center / 12th &amp; G St NW</td>\n",
" <td>38.898364</td>\n",
" <td>-77.027869</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31620</th>\n",
" <td>5th &amp; F St NW</td>\n",
" <td>38.897222</td>\n",
" <td>-77.019347</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31258</th>\n",
" <td>Lincoln Memorial</td>\n",
" <td>38.888251</td>\n",
" <td>-77.049426</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31217</th>\n",
" <td>USDA / 12th &amp; C St SW</td>\n",
" <td>38.886277</td>\n",
" <td>-77.028242</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" station_name latitude longitude\n",
"31608 8th & Eye St SE / Barracks Row 38.879200 -76.995300\n",
"31230 Metro Center / 12th & G St NW 38.898364 -77.027869\n",
"31620 5th & F St NW 38.897222 -77.019347\n",
"31258 Lincoln Memorial 38.888251 -77.049426\n",
"31217 USDA / 12th & C St SW 38.886277 -77.028242"
]
},
"execution_count": 110,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"merged_stations.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Flows"
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th>count</th>\n",
" </tr>\n",
" <tr>\n",
" <th>from_station</th>\n",
" <th>to_station</th>\n",
" <th>start_time</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"5\" valign=\"top\">31000</th>\n",
" <th rowspan=\"5\" valign=\"top\">31000</th>\n",
" <th>2018-07-04 02:00:00</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2018-07-04 20:00:00</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2018-07-06 11:00:00</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2018-07-07 11:00:00</th>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2018-07-08 10:00:00</th>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count\n",
"from_station to_station start_time \n",
"31000 31000 2018-07-04 02:00:00 1\n",
" 2018-07-04 20:00:00 1\n",
" 2018-07-06 11:00:00 2\n",
" 2018-07-07 11:00:00 4\n",
" 2018-07-08 10:00:00 1"
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hourly_starts = trip_data.groupby(['from_station', 'to_station', pd.Grouper(key='start_time', freq='60Min')]).size().to_frame('count')\n",
"\n",
"hourly_starts.head()"
]
},
{
"cell_type": "code",
"execution_count": 210,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(43097, 1)\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></th>\n",
" <th>count</th>\n",
" </tr>\n",
" <tr>\n",
" <th>from_station</th>\n",
" <th>to_station</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>31247</th>\n",
" <th>31247</th>\n",
" <td>911</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31248</th>\n",
" <th>31248</th>\n",
" <td>871</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31258</th>\n",
" <th>31249</th>\n",
" <td>801</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31288</th>\n",
" <th>31288</th>\n",
" <td>790</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31258</th>\n",
" <th>31258</th>\n",
" <td>732</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31247</th>\n",
" <th>31258</th>\n",
" <td>641</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31290</th>\n",
" <th>31258</th>\n",
" <td>639</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31240</th>\n",
" <th>31240</th>\n",
" <td>638</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31290</th>\n",
" <th>31290</th>\n",
" <td>636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31289</th>\n",
" <th>31289</th>\n",
" <td>614</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count\n",
"from_station to_station \n",
"31247 31247 911\n",
"31248 31248 871\n",
"31258 31249 801\n",
"31288 31288 790\n",
"31258 31258 732\n",
"31247 31258 641\n",
"31290 31258 639\n",
"31240 31240 638\n",
"31290 31290 636\n",
"31289 31289 614"
]
},
"execution_count": 210,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEACAYAAABYq7oeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEchJREFUeJzt3X+s3Xddx/Hny01GGQwZMze1XeyMFd2PGNzNnJKYm4xI\nEUIXxVkyXIfNGtwENE20NSb81WQkTmGLDCtgO10YdRJbwybO4gkxcZsdkJRtWWhYx1q7jd+zJAy7\nvP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XQ2CX5DeDDzF7K+smq2r6E29pfVdNLtX4NxrpMHmsymZajLhNzzqGq7gPuW6bN7Vim\n7WhxrMvksSaTacnrMjF7DpKkyTEp5xwkSRPEcJAkNQwHSVLDcACSnJ9kV5K/SXL9uOcjSPIzST6R\n5N5xz0UvSXJt9z75dJJfH/d8BEl+IcnHktyb5PdHtd4zNhySfDLJc0m+Mqd9XZInkhxMsrVr/k3g\n3qq6CXjHsk/2LLGYmlTV16pq03hmenZZZF3+qXufvBf4nXHM92ywyJo8XlXvBa4D3jSqOZyx4QDs\nBNb1N5zi7q+reeneTi8u4xzPNjtZeE20fHay+Lr8Wfe6lsZOFlGTJO8APssIPw5wxoZDVX0B+Pac\n5v+/+2tV/RA4cffXw8wGBJzBv5NxW2RNtEwWU5fM+hBwf1V9cbnnerZY7HulqvZW1VuBkR0WP9v+\nI5zv7q+rgM8Av5XkTibr9gFng3lrkuT1ST4GvDHJtvFM7ax2svfK+4A3A+9M8t5xTOwsdrL3ykyS\n25P8NSPcc5iYT0iPU1V9H3jPuOehl1TVt5g9rq0JUlW3A7ePex56SVX1gN6o13u27TkcAS7ue766\na9P4WJPJZF0mz7LW5GwLh0Hu/qqlZU0mk3WZPMtakzM2HJJ8CvhP4A1JDifZVFXHgT8APgc8Duyu\nqrlfGKQlYk0mk3WZPJNQE2+8J0lqnLF7DpKkwRkOkqSG4SBJahgOkqSG4SBJahgOkqSG4SBJahgO\nkqSG4SBJavwfxdivrRBN1w0AAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x12401aa20>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"overall_demand = trip_data.groupby(['from_station', 'to_station']).size().to_frame('count')\n",
"\n",
"print(overall_demand.shape)\n",
"overall_demand.head()\n",
"\n",
"log_count_bins = np.logspace(0, 3, 20)\n",
"overall_demand['count'].hist(bins=log_count_bins)\n",
"plt.xscale('log')\n",
"\n",
"overall_demand.sort_values('count', ascending=False).head(10)"
]
},
{
"cell_type": "code",
"execution_count": 165,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'#ffe600'"
]
},
"execution_count": 165,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import matplotlib as mpl\n",
"import matplotlib.cm as cm\n",
"\n",
"scalar_to_color = cm.ScalarMappable(norm=mpl.colors.LogNorm(vmin=1, vmax=1000), cmap=plt.get_cmap('jet'))\n",
"\n",
"\n",
"def count_to_color(count):\n",
" rgb = scalar_to_color.to_rgba(count)[:-1]\n",
" return mpl.colors.rgb2hex(rgb)\n",
"\n",
"count_to_color(100)"
]
},
{
"cell_type": "code",
"execution_count": 206,
"metadata": {},
"outputs": [],
"source": [
"def station_id_to_latlng(station_id):\n",
" return merged_stations.loc[station_id][['latitude', 'longitude']].values.tolist()\n",
"\n",
"polygons = [\n",
" Polygon(locations=[station_id_to_latlng(f), station_id_to_latlng(t)], \n",
" stroke=True, fill=True, opacity=.3, color=count_to_color(row['count']))\n",
" for (f, t), row in overall_demand.sort_values('count').tail(1000).iterrows()]\n"
]
},
{
"cell_type": "code",
"execution_count": 207,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eaa584348d894adab53d98abfd19923b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(basemap={'url': 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19, 'attribution': 'Map …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ipyleaflet import Map, Polygon, LayerGroup\n",
"\n",
"m = Map(center=(38.9, -77), zoom=10)\n",
"\n",
"m.add_layer(layer=LayerGroup(layers=polygons))\n",
"\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 211,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3af3b4b84ead40f19276f0d31b265fe3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(basemap={'url': 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19, 'attribution': 'Map …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ipyleaflet import Map, Marker, MarkerCluster\n",
"\n",
"m = Map(center=(38.9, -77), zoom=10)\n",
"\n",
"marker_cluster = MarkerCluster(\n",
" markers=[Marker(location=(row['latitude'], row['longitude']), title=str(row['terminal_number'])) for _, row in station_locations.iterrows()]\n",
")\n",
"m.add_layer(marker_cluster);\n",
"\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment