Reputation: 1230
I'm trying to iterate over a dataframe of international addresses in pandas, pass each row to geocoder, parse, and save the results. However, the same results are being returned for every row and I can't figure out why. When I try an example like 3327 WEST 2ND AVE VANCOUVER BC V6R,1
geocoder parses the value as expected but this iteration doesn't work.
import geocoder
g = 'GOOGLE_API_KEY'
for i, row in df.iterrows():
result = geocoder.google(df, key=g)
df.set_value(i, 'address', result.address)
df.set_value(i, 'city', result.city)
df.set_value(i, 'state', result.state)
df.set_value(i, 'postal', result.postal)
df.set_value(i, 'country', result.country)
Upvotes: 0
Views: 157
Reputation: 13715
It looks like you are not updating the query in each for loop
try replacing result = geocoder.google(df, key=g)
with result = geocoder.google(row, key=g)
import geocoder
g = 'GOOGLE_API_KEY'
for i, row in df.iterrows():
result = geocoder.google(row, key=g)
df.set_value(i, 'address', result.address)
df.set_value(i, 'city', result.city)
df.set_value(i, 'state', result.state)
df.set_value(i, 'postal', result.postal)
df.set_value(i, 'country', result.country)
Upvotes: 1