Created
August 27, 2019 03:10
-
-
Save sergiolucero/8f26a0b018cc95f984a591a94fd03e73 to your computer and use it in GitHub Desktop.
google places
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, pandas as pd | |
from creds import GOOGLE_KEY | |
GEO_BASE = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s' | |
def georef(address): #1600+Amphitheatre+Parkway,+Mountain+View,+CA | |
url = GEO_BASE %(address, GOOGLE_KEY) | |
res = requests.get(url).json().get('results') #returns a list | |
df = pd.DataFrame(res) | |
df['geometry'] = df['geometry'].apply(lambda geo: geo['location']) | |
df['lat'] = df['geometry'].apply(lambda geo: geo['lat']) | |
df['lon'] = df['geometry'].apply(lambda geo: geo['lng']) | |
df = df.drop(['address_components','geometry','place_id','types'], axis=1) | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment