import pandas as pd
t = pd.read_csv('terremotos.csv', usecols=[
'time', 'longitude', 'latitude', 'mag', 'place'], parse_dates=['time'])
t
from geopy.geocoders import GoogleV3
g = GoogleV3(api_key='AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w', timeout=3)
source_location = g.geocode('Universidad Tecnológica de Panamá')
source_location
source_location.latitude, source_location.longitude
from geopy.distance import vincenty as get_distance
target_location = g.geocode('Mercado de Mariscos, Cinta Costera')
get_distance(source_location.point, target_location.point).kilometers
from geopy.distance import vincenty as get_distance
def get_distance_in_km(x):
return pd.Series(get_distance(
(source_location.latitude, source_location.longitude),
(x.latitude, x.longitude)).kilometers)
t['distanceInKm'] = t.apply(get_distance_in_km, axis=1)
t = t.sort_values(['distanceInKm'])
t
from pysal.cg import RADIUS_EARTH_KM
from pysal.cg.kdtree import KDTree
tree = KDTree(t[['latitude', 'longitude']].values, distance_metric='Arc', radius=RADIUS_EARTH_KM)
distances, indices = tree.query((source_location.latitude, source_location.longitude), k=len(t))
distances
t.loc[indices]
Encuentre una tabla en http://www.datosabiertos.gob.pa. Añada una columna con distancia en kilometros de la Universidad Tecnológica de Panamá.
Ejemplo: Puntos de acceso de la red nacional de internet
pd.read_csv('http://www.datosabiertos.gob.pa/dataset/97111990-73c2-42e7-8a45-6dfb26ad20cb/resource/7ca7059e-ea8d-4ca4-8765-f43faa3952b3/download/rni-feb2017-csv.csv', encoding='ISO-8859-1')