0

I have a Pandas dataframe, and I'm calling a geopy function on each row of 'address_original' column to get as much detail as possible about every address

from geopy.geocoders import GoogleV3

geolocator = GoogleV3(api_key='', timeout=5, 
                      )

df['full_address_geocoded'] = df['address_original'].progress_apply(geolocator.geocode())
print df['full_address_geocoded'][:5]

0    (Veale Rd, New Plymouth, New Zealand, (-39.095...
1    (Veale Rd, Delaware, USA, (39.8036422, -75.494...
2    (1068 Clearwater Valley Rd, Clearwater, BC V0E...
3    (1605 Pine St W, Stillwater, MN 55082, USA, (4...
4                                                 None

The issue is that I need more information than there is included when using geocode method. Geopy also has .raw function, which works perfectly on a single string and outputs the data about what region the address belong to, area, etc.

places = '1238 Davie St, Vancouver, BC'


geolocator = GoogleV3(api_key='AIzaSyBlNIvZTk-BpWDeX1FFXPbx6QwbNzZL80w')
location = geolocator.geocode(places, language='en')
print location.raw

{u'geometry': {u'location_type': u'ROOFTOP', u'bounds': {u'northeast': {u'lat': 50.6539919, u'lng': -120.3383232}, u'southwest': {u'lat': 50.6538198, u'lng': -120.3386968}}, u'viewport': {u'northeast': {u'lat': 50.6552548302915, u'lng': -120.3371610197085}, u'southwest': {u'lat': 50.6525568697085, u'lng': -120.3398589802915}}, u'location': {u'lat': 50.6539239, u'lng': -120.3385242}}, u'address_components': [{u'long_name': u'142', u'types': [u'street_number'], u'short_name': u'142'}, {u'long_name': u'Waddington Drive', u'types': [u'route'], u'short_name': u'Waddington Dr'}, {u'long_name': u'Upper Sahali', u'types': [u'neighborhood', u'political'], u'short_name': u'Upper Sahali'}, {u'long_name': u'Kamloops', u'types': [u'locality', u'political'], u'short_name': u'Kamloops'}, {u'long_name': u'Thompson-Nicola', u'types': [u'administrative_area_level_2', u'political'], u'short_name': u'Thompson-Nicola'}, {u'long_name': u'British Columbia', u'types': [u'administrative_area_level_1', u'political'], u'short_name': u'BC'}, {u'long_name': u'Canada', u'types': [u'country', u'political'], u'short_name': u'CA'}, {u'long_name': u'V2E 1N3', u'types': [u'postal_code'], u'short_name': u'V2E 1N3'}], u'place_id': u'ChIJaV6wtDgsflMR1J9ReM0lzLs', u'formatted_address': u'142 Waddington Dr, Kamloops, BC V2E 1N3, Canada', u'types': [u'premise']}

The raw method doesn't work on multiple values, however, I get the TypeError: 'dict' object is not callable.

What is a way around this?

  • Please show the code that produce the error message – BERA Jun 22 at 17:05
1

Try:

import pandas as pd
from geopy.geocoders import GoogleV3

adresslist = r'https://gist.githubusercontent.com/HeroicEric/1102788/raw/0bcb298bd75513a398bf353ce7162177350813c9/gistfile1.txt'
df = pd.read_csv(adresslist, names=['firstpart','secondpart'])
df['adress_original'] = df['firstpart']+df['secondpart']

geolocator = GoogleV3(api_key='AIzaSyBlNIvZTk-BpWDeX1FFXPbx6QwbNzZL80w')
df['adress_original'].head(5).apply(lambda x: geolocator.geocode(x, language='en').raw)

0    {'address_components': [{'long_name': '777', '...
1    {'address_components': [{'long_name': '30', 's...
2    {'address_components': [{'long_name': '250', '...
3    {'address_components': [{'long_name': '700', '...
4    {'address_components': [{'long_name': '66', 's...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.