Reputation: 3
I'm trying to add values into a new pandas column sp['New Address']
by using a Google Maps API Key and a for-loop that uses the addresses in the column sp['ASL Address (PAPER)-REFERENCE']
as a string query.
I've tried to create an empty list (addresses
) that appends the searched addresses when the for-loop is run, and then run another for-loop that is supposed to loop through each row in sp['New Address']
and paste the addresses searched in the original for-loop:
for address in sp['ASL Address (PAPER)-REFERENCE']:
api_key = "API Key"
url = "https://maps.googleapis.com/maps/api/place/textsearch/json?"
query = address
r = requests.get(url + 'query=' + query + '&key=' + api_key)
x = r.json()
z = x['results']
for i in range(len(z)):
for row in sp['New Address']:
addresses = []
sp['New Address'] = addresses.append((z[i]['formatted_address']))
I expected the rows in sp['New Address']
to be filled with an address such as '21 Laurel Brook Rd, Middletown, CT 06457, USA'. However whenever I run the code, sp['New Address']
is still empty.
Upvotes: 0
Views: 504
Reputation: 33940
Your bug is simply that .append()
on a list always returns None
, because it works in-place
(But if you'd attempted to debug this with a few humble print statements in each loop, you would have found that by yourself)
Upvotes: 1