0

I am trying to loop through a dataframe of latitudes and longitudes to find the postcodes for each row, using geocoder (method: reverse), however, I get the error "TypeError: cannot convert the series to"

This is my code

import pandas as pd
df = pd.read_csv("Bunnings Co-Ordinates.csv")

import geocoder

for Store in df["Store"]:
    g = geocoder.google([df["Latitude"], df["Longitude"]], method='reverse', key="API_KEY")
    print(g.postal)

and I get the error "TypeError: cannot convert the series to".

I originally tried to loop through a list of co-ordinates using this code;

import geocoder
coordinates = [-27.59041, 153.02848, -34.93522, 138.53637]
latitudes = [-27.59041, -34.93522]
longitudes = [153.02848, 138.53637]

for coordinate in coordinates:
    g = geocoder.google([latitudes, longitudes], method='reverse', key="API_KEY")
    print(g.postal)

and I got this error: "TypeError: float() argument must be a string or a number, not 'list'"

  • Please explain " for coordinate in coordinates:" - why are you using coordinates for, for loop and secondly you are assigning list inside the list instead of string or number – Himanshu Panwar Jun 13 '23 at 07:26

1 Answers1

0

If you want to assign latitude and longitude the try this:

latitudes = [-27.59041, -34.93522]
longitudes = [153.02848, 138.53637]

for lat,long in zip(latitudes,longitudes):
    g = geocoder.google([lat, long], method='reverse', key="API_KEY")
    print(g.postal)
Himanshu Panwar
  • 216
  • 2
  • 7