#crosscompute
#copy the prevoius code
#get dataset nyc data: nyc hotspots
#show map of ten hotspots near you
searches = 10
address = '85-52 168th street'
url = 'https://data.cityofnewyork.us/api/views/yjub-udmw/rows.csv?accessType=DOWNLOAD'
target_folder = '/tmp'
import pandas as pd
table = pd.read_csv(url)
import geopy
# Convert address to latitude and longitude
geocode = geopy.GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
search_location = geocode(address)
search_latlon = search_location.latitude, search_location.longitude
search_latlon
import pip
pip.main(['install', 'pysal'])
table.iloc[0]
source_latlons = table[['Latitude', 'Longitude']].values
from pysal.cg import RADIUS_EARTH_MILES
from pysal.cg.kdtree import KDTree
source_tree = KDTree(source_latlons, distance_metric='Arc', radius=RADIUS_EARTH_MILES)
distances, indices = source_tree.query(search_latlon, k=searches)
print(distances)
print(indices)
var = table[['Latitude', 'Longitude','Borough']]
var[:3]
location = table.iloc[indices].copy()
from os.path import join
target_path = join(target_folder, 'locations.csv')
location.to_csv(target_path, index=False)
print('selected_location_geotable_path = %s' % target_path)