Skip to content

Instantly share code, notes, and snippets.

@Zedmor
Created September 25, 2016 04:38
Show Gist options
  • Save Zedmor/8e3abbdee718f4c8d921892365629c27 to your computer and use it in GitHub Desktop.
Save Zedmor/8e3abbdee718f4c8d921892365629c27 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Custom data range API requests - one month scope"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#!/usr/bin/env python\n",
"\n",
"# make sure to install these packages before running:\n",
"# pip install pandas\n",
"# pip install bokeh\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"import datetime\n",
"import urllib\n",
"\n",
"from bokeh.plotting import *\n",
"from bokeh.models import HoverTool\n",
"from collections import OrderedDict\n",
"\n",
"query = (\"https://data.phila.gov/resource/4t9v-rppq.json?$where=requested_datetime%20between%20%272016-09-01T00:00:00%27%20and%20%272016-10-01T00:00:00%27\")\n",
"raw_data = pd.read_json(query)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"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>address</th>\n",
" <th>agency_responsible</th>\n",
" <th>expected_datetime</th>\n",
" <th>lat</th>\n",
" <th>lon</th>\n",
" <th>media_url</th>\n",
" <th>requested_datetime</th>\n",
" <th>service_code</th>\n",
" <th>service_name</th>\n",
" <th>service_notice</th>\n",
" <th>shape</th>\n",
" <th>status</th>\n",
" <th>updated_datetime</th>\n",
" <th>zipcode</th>\n",
" </tr>\n",
" <tr>\n",
" <th>service_request_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>10916643</th>\n",
" <td>915 N BROAD ST</td>\n",
" <td>Streets Department</td>\n",
" <td>2016-09-04T20:00:00.000</td>\n",
" <td>39.970700</td>\n",
" <td>-75.159593</td>\n",
" <td>NaN</td>\n",
" <td>2016-09-01T06:56:29.000</td>\n",
" <td>SR-ST01</td>\n",
" <td>Street Defect</td>\n",
" <td>None</td>\n",
" <td>{'coordinates': [-75.159593, 39.9707], 'type':...</td>\n",
" <td>Closed</td>\n",
" <td>2016-09-01T06:56:38.000</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10917293</th>\n",
" <td>NaN</td>\n",
" <td>Philly311 Contact Center</td>\n",
" <td>2016-09-06T13:05:26.000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2016-09-01T11:11:02.000</td>\n",
" <td>SR-MI01</td>\n",
" <td>Miscellaneous</td>\n",
" <td>None</td>\n",
" <td>NaN</td>\n",
" <td>Open</td>\n",
" <td>2016-09-01T11:11:03.000</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10916656</th>\n",
" <td>6824 TORRESDALE AVE</td>\n",
" <td>Streets Department</td>\n",
" <td>2016-09-06T20:00:00.000</td>\n",
" <td>40.025615</td>\n",
" <td>-75.043901</td>\n",
" <td>https://d17aqltn7cihbm.cloudfront.net/uploads/...</td>\n",
" <td>2016-09-01T08:01:55.000</td>\n",
" <td>SR-ST02</td>\n",
" <td>Illegal Dumping</td>\n",
" <td>5 Business Days</td>\n",
" <td>{'coordinates': [-75.043901, 40.025615], 'type...</td>\n",
" <td>Closed</td>\n",
" <td>2016-09-01T12:02:36.000</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10918749</th>\n",
" <td>5231 HAVERFORD AVE</td>\n",
" <td>Community Life Improvement Program</td>\n",
" <td>2017-01-05T19:00:00.000</td>\n",
" <td>39.965571</td>\n",
" <td>-75.226215</td>\n",
" <td>NaN</td>\n",
" <td>2016-09-01T18:27:56.000</td>\n",
" <td>SR-CL02</td>\n",
" <td>Vacant Lot Clean-Up</td>\n",
" <td>90 Business Days</td>\n",
" <td>{'coordinates': [-75.226215, 39.965571], 'type...</td>\n",
" <td>Open</td>\n",
" <td>2016-09-01T18:30:37.000</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10917583</th>\n",
" <td>2027 FITZWATER ST</td>\n",
" <td>License &amp; Inspections</td>\n",
" <td>2016-09-28T20:00:00.000</td>\n",
" <td>39.943106</td>\n",
" <td>-75.176295</td>\n",
" <td>NaN</td>\n",
" <td>2016-09-01T12:21:11.000</td>\n",
" <td>SR-LI27</td>\n",
" <td>Vacant House or Commercial</td>\n",
" <td>20 Business Days</td>\n",
" <td>{'coordinates': [-75.176295, 39.943106], 'type...</td>\n",
" <td>Open</td>\n",
" <td>2016-09-01T20:32:23.000</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" address agency_responsible \\\n",
"service_request_id \n",
"10916643 915 N BROAD ST Streets Department \n",
"10917293 NaN Philly311 Contact Center \n",
"10916656 6824 TORRESDALE AVE Streets Department \n",
"10918749 5231 HAVERFORD AVE Community Life Improvement Program \n",
"10917583 2027 FITZWATER ST License & Inspections \n",
"\n",
" expected_datetime lat lon \\\n",
"service_request_id \n",
"10916643 2016-09-04T20:00:00.000 39.970700 -75.159593 \n",
"10917293 2016-09-06T13:05:26.000 NaN NaN \n",
"10916656 2016-09-06T20:00:00.000 40.025615 -75.043901 \n",
"10918749 2017-01-05T19:00:00.000 39.965571 -75.226215 \n",
"10917583 2016-09-28T20:00:00.000 39.943106 -75.176295 \n",
"\n",
" media_url \\\n",
"service_request_id \n",
"10916643 NaN \n",
"10917293 NaN \n",
"10916656 https://d17aqltn7cihbm.cloudfront.net/uploads/... \n",
"10918749 NaN \n",
"10917583 NaN \n",
"\n",
" requested_datetime service_code \\\n",
"service_request_id \n",
"10916643 2016-09-01T06:56:29.000 SR-ST01 \n",
"10917293 2016-09-01T11:11:02.000 SR-MI01 \n",
"10916656 2016-09-01T08:01:55.000 SR-ST02 \n",
"10918749 2016-09-01T18:27:56.000 SR-CL02 \n",
"10917583 2016-09-01T12:21:11.000 SR-LI27 \n",
"\n",
" service_name service_notice \\\n",
"service_request_id \n",
"10916643 Street Defect None \n",
"10917293 Miscellaneous None \n",
"10916656 Illegal Dumping 5 Business Days \n",
"10918749 Vacant Lot Clean-Up 90 Business Days \n",
"10917583 Vacant House or Commercial 20 Business Days \n",
"\n",
" shape status \\\n",
"service_request_id \n",
"10916643 {'coordinates': [-75.159593, 39.9707], 'type':... Closed \n",
"10917293 NaN Open \n",
"10916656 {'coordinates': [-75.043901, 40.025615], 'type... Closed \n",
"10918749 {'coordinates': [-75.226215, 39.965571], 'type... Open \n",
"10917583 {'coordinates': [-75.176295, 39.943106], 'type... Open \n",
"\n",
" updated_datetime zipcode \n",
"service_request_id \n",
"10916643 2016-09-01T06:56:38.000 NaN \n",
"10917293 2016-09-01T11:11:03.000 NaN \n",
"10916656 2016-09-01T12:02:36.000 NaN \n",
"10918749 2016-09-01T18:30:37.000 NaN \n",
"10917583 2016-09-01T20:32:23.000 NaN "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"raw_data=raw_data.set_index(['service_request_id'])\n",
"raw_data.head()"
]
}
],
"metadata": {
"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