Skip to content

Instantly share code, notes, and snippets.

@gregorydillon
Created April 22, 2017 23:50
Show Gist options
  • Save gregorydillon/8c8e06dd07147efb9c7b465f66f93168 to your computer and use it in GitHub Desktop.
Save gregorydillon/8c8e06dd07147efb9c7b465f66f93168 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"language_info": {
"nbconvert_exporter": "python",
"version": "2.7.11",
"file_extension": ".py",
"codemirror_mode": {
"version": 2,
"name": "ipython"
},
"mimetype": "text/x-python",
"pygments_lexer": "ipython2",
"name": "python"
},
"kernelspec": {
"display_name": "Python 2 with Spark 2.0",
"language": "python",
"name": "python2-spark20"
}
},
"nbformat": 4,
"cells": [
{
"metadata": {
"collapsed": false
},
"outputs": [],
"cell_type": "code",
"execution_count": 84,
"source": "import numpy as np\nimport pandas as pd\nimport datetime\nimport urllib\nimport json\n \nfrom bokeh.plotting import *\nfrom bokeh.models import HoverTool\nfrom collections import OrderedDict\n\nquery = (\"https://data.sfgov.org/resource/rs7u-hch9.json?$limit=50000\")\nraw_data = pd.read_json(query)\t"
},
{
"metadata": {
"collapsed": false
},
"outputs": [
{
"metadata": {},
"output_type": "execute_result",
"execution_count": 85,
"data": {
"text/plain": "(50000, 19)"
}
}
],
"cell_type": "code",
"execution_count": 85,
"source": "raw_data.shape"
},
{
"metadata": {
"collapsed": false
},
"outputs": [
{
"metadata": {},
"output_type": "execute_result",
"execution_count": 88,
"data": {
"text/plain": "Index([u'address', u'agency_responsible', u'closed_date', u'lat', u'long',\n u'media_url', u'neighborhoods_sffind_boundaries', u'point',\n u'police_district', u'requested_datetime', u'service_details',\n u'service_name', u'service_request_id', u'service_subtype', u'source',\n u'status_description', u'status_notes', u'supervisor_district',\n u'updated_datetime'],\n dtype='object')"
}
}
],
"cell_type": "code",
"execution_count": 88,
"source": "raw_data.columns"
},
{
"metadata": {},
"cell_type": "raw",
"source": ""
},
{
"metadata": {
"collapsed": false
},
"outputs": [
{
"metadata": {},
"output_type": "execute_result",
"execution_count": 90,
"data": {
"text/plain": "(50000, 19)"
}
}
],
"cell_type": "code",
"execution_count": 90,
"source": "raw_data.shape"
},
{
"metadata": {
"collapsed": false
},
"outputs": [
{
"metadata": {},
"output_type": "execute_result",
"execution_count": 91,
"data": {
"text/plain": " address agency_responsible \\\n0 1324 PINE ST, SAN FRANCISCO, CA, 94109 DPW Ops Queue \n1 575 BERRY ST, SAN FRANCISCO, CA, 94107 DPW Ops Queue \n2 Intersection of GEARY BLVD and STEINER ST DPW Ops Queue \n3 Intersection of EDDY ST and JONES ST DPW Ops Queue \n4 2135 MISSION ST, SAN FRANCISCO, CA, 94110 DPW Ops Queue \n\n closed_date lat long \\\n0 2016-04-23T16:26:24 37.79019 -122.4177 \n1 2016-04-23T09:52:56 37.76987 -122.4009 \n2 2016-04-23T11:43:08 37.78378 -122.4347 \n3 2016-04-23T09:52:41 37.78413 -122.4126 \n4 2016-04-23T15:38:36 37.76284 -122.4192 \n\n media_url \\\n0 {u'url': u'http://mobile311.sfgov.org/media/sa... \n1 {u'url': u'http://mobile311.sfgov.org/media/sa... \n2 {u'url': u'http://mobile311.sfgov.org/media/sa... \n3 {u'url': u'http://mobile311.sfgov.org/media/sa... \n4 {u'url': u'http://mobile311.sfgov.org/media/sa... \n\n neighborhoods_sffind_boundaries \\\n0 Nob Hill \n1 South Beach \n2 Western Addition \n3 Tenderloin \n4 Mission \n\n point police_district \\\n0 {u'latitude': u'37.790091242147', u'needs_reco... CENTRAL \n1 {u'latitude': u'37.780111844747', u'needs_reco... SOUTHERN \n2 {u'latitude': u'37.7841518790467', u'needs_rec... NORTHERN \n3 {u'latitude': u'37.7839325967532', u'needs_rec... TENDERLOIN \n4 {u'latitude': u'37.762847749236', u'needs_reco... MISSION \n\n requested_datetime service_details service_name \\\n0 2016-04-23T06:56:40 Needles Homeless Concerns \n1 2016-04-23T07:05:54 Encampment Cleanup Encampments \n2 2016-04-23T07:32:56 Encampment Cleanup Encampments \n3 2016-04-23T08:12:53 Needles Homeless Concerns \n4 2016-04-23T08:13:13 Needles Homeless Concerns \n\n service_request_id service_subtype source status_description \\\n0 5791832 Medical Waste Mobile/Open311 Closed \n1 5791837 Encampment Reports Mobile/Open311 Closed \n2 5791850 Encampment Reports Mobile/Open311 Closed \n3 5791888 Medical Waste Mobile/Open311 Closed \n4 5791890 Medical Waste Mobile/Open311 Closed \n\n status_notes supervisor_district \\\n0 Case Resolved - done 3 \n1 Area Cleaned - Completed by zone personnel 6 \n2 Area Cleaned - 5 \n3 Case Resolved - Completed by zone personnel 6 \n4 Case Resolved - 10-98 9 \n\n updated_datetime \n0 2016-04-23T16:26:24 \n1 2016-04-23T09:52:56 \n2 2016-04-23T11:43:08 \n3 2016-04-23T09:52:41 \n4 2016-04-23T15:38:36 ",
"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>closed_date</th>\n <th>lat</th>\n <th>long</th>\n <th>media_url</th>\n <th>neighborhoods_sffind_boundaries</th>\n <th>point</th>\n <th>police_district</th>\n <th>requested_datetime</th>\n <th>service_details</th>\n <th>service_name</th>\n <th>service_request_id</th>\n <th>service_subtype</th>\n <th>source</th>\n <th>status_description</th>\n <th>status_notes</th>\n <th>supervisor_district</th>\n <th>updated_datetime</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1324 PINE ST, SAN FRANCISCO, CA, 94109</td>\n <td>DPW Ops Queue</td>\n <td>2016-04-23T16:26:24</td>\n <td>37.79019</td>\n <td>-122.4177</td>\n <td>{u'url': u'http://mobile311.sfgov.org/media/sa...</td>\n <td>Nob Hill</td>\n <td>{u'latitude': u'37.790091242147', u'needs_reco...</td>\n <td>CENTRAL</td>\n <td>2016-04-23T06:56:40</td>\n <td>Needles</td>\n <td>Homeless Concerns</td>\n <td>5791832</td>\n <td>Medical Waste</td>\n <td>Mobile/Open311</td>\n <td>Closed</td>\n <td>Case Resolved - done</td>\n <td>3</td>\n <td>2016-04-23T16:26:24</td>\n </tr>\n <tr>\n <th>1</th>\n <td>575 BERRY ST, SAN FRANCISCO, CA, 94107</td>\n <td>DPW Ops Queue</td>\n <td>2016-04-23T09:52:56</td>\n <td>37.76987</td>\n <td>-122.4009</td>\n <td>{u'url': u'http://mobile311.sfgov.org/media/sa...</td>\n <td>South Beach</td>\n <td>{u'latitude': u'37.780111844747', u'needs_reco...</td>\n <td>SOUTHERN</td>\n <td>2016-04-23T07:05:54</td>\n <td>Encampment Cleanup</td>\n <td>Encampments</td>\n <td>5791837</td>\n <td>Encampment Reports</td>\n <td>Mobile/Open311</td>\n <td>Closed</td>\n <td>Area Cleaned - Completed by zone personnel</td>\n <td>6</td>\n <td>2016-04-23T09:52:56</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Intersection of GEARY BLVD and STEINER ST</td>\n <td>DPW Ops Queue</td>\n <td>2016-04-23T11:43:08</td>\n <td>37.78378</td>\n <td>-122.4347</td>\n <td>{u'url': u'http://mobile311.sfgov.org/media/sa...</td>\n <td>Western Addition</td>\n <td>{u'latitude': u'37.7841518790467', u'needs_rec...</td>\n <td>NORTHERN</td>\n <td>2016-04-23T07:32:56</td>\n <td>Encampment Cleanup</td>\n <td>Encampments</td>\n <td>5791850</td>\n <td>Encampment Reports</td>\n <td>Mobile/Open311</td>\n <td>Closed</td>\n <td>Area Cleaned -</td>\n <td>5</td>\n <td>2016-04-23T11:43:08</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Intersection of EDDY ST and JONES ST</td>\n <td>DPW Ops Queue</td>\n <td>2016-04-23T09:52:41</td>\n <td>37.78413</td>\n <td>-122.4126</td>\n <td>{u'url': u'http://mobile311.sfgov.org/media/sa...</td>\n <td>Tenderloin</td>\n <td>{u'latitude': u'37.7839325967532', u'needs_rec...</td>\n <td>TENDERLOIN</td>\n <td>2016-04-23T08:12:53</td>\n <td>Needles</td>\n <td>Homeless Concerns</td>\n <td>5791888</td>\n <td>Medical Waste</td>\n <td>Mobile/Open311</td>\n <td>Closed</td>\n <td>Case Resolved - Completed by zone personnel</td>\n <td>6</td>\n <td>2016-04-23T09:52:41</td>\n </tr>\n <tr>\n <th>4</th>\n <td>2135 MISSION ST, SAN FRANCISCO, CA, 94110</td>\n <td>DPW Ops Queue</td>\n <td>2016-04-23T15:38:36</td>\n <td>37.76284</td>\n <td>-122.4192</td>\n <td>{u'url': u'http://mobile311.sfgov.org/media/sa...</td>\n <td>Mission</td>\n <td>{u'latitude': u'37.762847749236', u'needs_reco...</td>\n <td>MISSION</td>\n <td>2016-04-23T08:13:13</td>\n <td>Needles</td>\n <td>Homeless Concerns</td>\n <td>5791890</td>\n <td>Medical Waste</td>\n <td>Mobile/Open311</td>\n <td>Closed</td>\n <td>Case Resolved - 10-98</td>\n <td>9</td>\n <td>2016-04-23T15:38:36</td>\n </tr>\n </tbody>\n</table>\n</div>"
}
}
],
"cell_type": "code",
"execution_count": 91,
"source": "raw_data.head(5)"
},
{
"metadata": {
"collapsed": false
},
"outputs": [
{
"metadata": {},
"output_type": "execute_result",
"execution_count": 62,
"data": {
"text/plain": "Empty DataFrame\nColumns: []\nIndex: []",
"text/html": "<div>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n </tr>\n </thead>\n <tbody>\n </tbody>\n</table>\n</div>"
}
}
],
"cell_type": "code",
"execution_count": 62,
"source": "\n"
},
{
"metadata": {
"collapsed": false
},
"outputs": [],
"cell_type": "code",
"execution_count": null,
"source": "\n\n"
},
{
"metadata": {
"collapsed": false
},
"outputs": [],
"cell_type": "code",
"execution_count": null,
"source": ""
},
{
"metadata": {
"collapsed": true
},
"outputs": [],
"cell_type": "code",
"execution_count": null,
"source": ""
}
],
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment