Skip to content

Instantly share code, notes, and snippets.

@lvngd
Last active June 13, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvngd/7bf2339edaa9015a542c453672524850 to your computer and use it in GitHub Desktop.
Save lvngd/7bf2339edaa9015a542c453672524850 to your computer and use it in GitHub Desktop.
import requests
import pandas as pd
"""
Script to fetch 50,000 311 noise complaints from NYC Open Data.
Substitute your own API key.
"""
NYC_OPEN_DATA_API_KEY='xxxxxxxxxx'
date = '2020-01-15'
#311 complaints endpoint
endpoint = "https://data.cityofnewyork.us/resource/erm2-nwe9.json?$where=created_date<'{}' AND complaint_type like 'Noise%25'&$limit=50000".format(date)
headers={'X-App-Token': NYC_OPEN_DATA_API_KEY}
result = requests.get(endpoint, headers=headers)
noise_complaints = pd.DataFrame(result.json())
#drop irrelevant columns
columns_to_drop = ['address_type', 'agency',
'bbl', 'community_board',
'cross_street_1', 'cross_street_2', 'due_date',
'facility_type', 'landmark',
'intersection_street_1', 'intersection_street_2','location',
'open_data_channel_type', 'park_borough', 'park_facility_name',
'resolution_action_updated_date','unique_key',
'x_coordinate_state_plane', 'y_coordinate_state_plane','city', 'street_name']
noise_complaints.drop(columns_to_drop,inplace=True,axis=1)
#filter for status == 'Closed' then drop status column
noise_complaints = noise_complaints[noise_complaints.status == 'Closed']
noise_complaints.drop(['status'],inplace=True,axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment