-1

I'm importing a CSV into a pandas data frame, and then I'm trying to create three new columns in that data frame from data retrieved from geopy.geocoders.GoogleV3() :

import pandas from geopy.geocoders import GoogleV3

DATA = pandas.read_csv("file/to/csv") 
geolocator = GoogleV3()

DATA.googleaddress, (DATA.latitude, DATA.longitude) = geolocator.geocode(DATA.address)

Problem is I keep getting this error:

Traceback (most recent call last):
  File "C:/Path/To/GeoCoder.py", line 9, in <module>
    DATA.googleaddress, (DATA.latitude, DATA.longitude) = geolocator.geocode(DATA.address)
TypeError: 'NoneType' object is not iterable

What does this error mean and how do I get around it?

admdrew
  • 3,790
  • 4
  • 27
  • 39
gtnbz2nyt
  • 1,465
  • 3
  • 17
  • 33

1 Answers1

1

Because geolocator.geocode expects a single argument at a time, not a list (or array).

You could try:

locs = [ geolocator.geocode(addr) for addr in DATA.address ]
geo_info = pandas.DataFrame(
    [ (addr.address, addr.latitude, addr.longitude) for addr in locs ],
    columns=['googleaddress', 'latitude', 'longitude'])

All you would have to do is merge these DataFrames:

DATA.combine_first(geo_info)

Nnote that it is considered bad form to have an all-uppercase variable in python.

Oliver W.
  • 13,169
  • 3
  • 37
  • 50
  • Well alright that did something! Thanks, but now I get an error: 'too many variables to unpack' ... guessing it's because I'm passing too many addresses? but it's only 27 for now... – gtnbz2nyt Dec 11 '14 at 20:05
  • No, it's because you have a list of 27 `Location` instances, that you're trying to [unpack](https://docs.python.org/2/tutorial/controlflow.html#tut-unpacking-arguments) to 2 elements (one of which, a tuple). I'll update the answer. – Oliver W. Dec 11 '14 at 20:29