Skip to content

Instantly share code, notes, and snippets.

@EthanRosenthal
Created February 17, 2017 15:45
Show Gist options
  • Save EthanRosenthal/bf7a479de2cdc7d95c67d2263ebd8a80 to your computer and use it in GitHub Desktop.
Save EthanRosenthal/bf7a479de2cdc7d95c67d2263ebd8a80 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": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import datetime\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"import numpy as np\n",
"import pandas as pd\n",
"import dask.dataframe as dd\n",
"import collections\n",
"\n",
"mpl.rcParams['axes.labelsize'] = 20\n",
"mpl.rcParams['axes.titlesize'] = 24\n",
"mpl.rcParams['xtick.labelsize'] = 16\n",
"mpl.rcParams['ytick.labelsize'] = 16\n",
"mpl.rcParams['legend.fontsize'] = 16"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>execution_time</th>\n",
" <th>available_bikes</th>\n",
" <th>available_docks</th>\n",
" <th>id</th>\n",
" <th>last_communication_time</th>\n",
" <th>lat</th>\n",
" <th>lon</th>\n",
" <th>st_address</th>\n",
" <th>station_name</th>\n",
" <th>status_key</th>\n",
" <th>status_value</th>\n",
" <th>test_station</th>\n",
" <th>total_docks</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2016-09-18 16:59:51</td>\n",
" <td>3</td>\n",
" <td>36</td>\n",
" <td>72</td>\n",
" <td>2016-09-18 16:58:36</td>\n",
" <td>40.767272</td>\n",
" <td>-73.993929</td>\n",
" <td>W 52 St &amp; 11 Ave</td>\n",
" <td>W 52 St &amp; 11 Ave</td>\n",
" <td>1</td>\n",
" <td>In Service</td>\n",
" <td>f</td>\n",
" <td>39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2016-09-18 16:59:51</td>\n",
" <td>12</td>\n",
" <td>19</td>\n",
" <td>79</td>\n",
" <td>2016-09-18 16:57:02</td>\n",
" <td>40.719116</td>\n",
" <td>-74.006667</td>\n",
" <td>Franklin St &amp; W Broadway</td>\n",
" <td>Franklin St &amp; W Broadway</td>\n",
" <td>1</td>\n",
" <td>In Service</td>\n",
" <td>f</td>\n",
" <td>33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2016-09-18 16:59:51</td>\n",
" <td>22</td>\n",
" <td>5</td>\n",
" <td>82</td>\n",
" <td>2016-09-18 16:59:26</td>\n",
" <td>40.711174</td>\n",
" <td>-74.000165</td>\n",
" <td>St James Pl &amp; Pearl St</td>\n",
" <td>St James Pl &amp; Pearl St</td>\n",
" <td>1</td>\n",
" <td>In Service</td>\n",
" <td>f</td>\n",
" <td>27</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2016-09-18 16:59:51</td>\n",
" <td>2</td>\n",
" <td>58</td>\n",
" <td>83</td>\n",
" <td>2016-09-18 16:57:32</td>\n",
" <td>40.683826</td>\n",
" <td>-73.976323</td>\n",
" <td>Atlantic Ave &amp; Fort Greene Pl</td>\n",
" <td>Atlantic Ave &amp; Fort Greene Pl</td>\n",
" <td>1</td>\n",
" <td>In Service</td>\n",
" <td>f</td>\n",
" <td>62</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2016-09-18 16:59:51</td>\n",
" <td>1</td>\n",
" <td>38</td>\n",
" <td>116</td>\n",
" <td>2016-09-18 16:59:05</td>\n",
" <td>40.741776</td>\n",
" <td>-74.001497</td>\n",
" <td>W 17 St &amp; 8 Ave</td>\n",
" <td>W 17 St &amp; 8 Ave</td>\n",
" <td>1</td>\n",
" <td>In Service</td>\n",
" <td>f</td>\n",
" <td>39</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" execution_time available_bikes available_docks id \\\n",
"0 2016-09-18 16:59:51 3 36 72 \n",
"1 2016-09-18 16:59:51 12 19 79 \n",
"2 2016-09-18 16:59:51 22 5 82 \n",
"3 2016-09-18 16:59:51 2 58 83 \n",
"4 2016-09-18 16:59:51 1 38 116 \n",
"\n",
" last_communication_time lat lon \\\n",
"0 2016-09-18 16:58:36 40.767272 -73.993929 \n",
"1 2016-09-18 16:57:02 40.719116 -74.006667 \n",
"2 2016-09-18 16:59:26 40.711174 -74.000165 \n",
"3 2016-09-18 16:57:32 40.683826 -73.976323 \n",
"4 2016-09-18 16:59:05 40.741776 -74.001497 \n",
"\n",
" st_address station_name status_key \\\n",
"0 W 52 St & 11 Ave W 52 St & 11 Ave 1 \n",
"1 Franklin St & W Broadway Franklin St & W Broadway 1 \n",
"2 St James Pl & Pearl St St James Pl & Pearl St 1 \n",
"3 Atlantic Ave & Fort Greene Pl Atlantic Ave & Fort Greene Pl 1 \n",
"4 W 17 St & 8 Ave W 17 St & 8 Ave 1 \n",
"\n",
" status_value test_station total_docks \n",
"0 In Service f 39 \n",
"1 In Service f 33 \n",
"2 In Service f 27 \n",
"3 In Service f 62 \n",
"4 In Service f 39 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ddf = dd.read_csv('dat_20160918_20170214.csv', **{'sep': '|'})\n",
"ddf.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"howard, macdougal = dd.compute(ddf.query('station_name == \"Howard St & Centre St\"'),\n",
" ddf.query('station_name == \"MacDougal St & Prince St\"'))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def cleanup(df):\n",
" df = df.set_index('execution_time', drop=True)\n",
" df.index = pd.to_datetime(df.index)\n",
" df.sort_index(inplace=True)\n",
" return df\n",
"\n",
"howard = cleanup(howard)\n",
"macdougal = cleanup(macdougal)"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [Root]",
"language": "python",
"name": "Python [Root]"
},
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment