Search code examples
pythonnumpygoogle-geocoder

why return value is only nan?


Here is my code I am trying to run, but i am not getting the values in output,

import numpy
import geocoder

data = numpy.loadtxt(fname = 'Flywheel_SF.csv', delimiter = ',', dtype = numpy.ndarray)
start = list()
end = list()
z_code = numpy.zeros((101,2))

for i in range(1,101):
    s = geocoder.google([data[i,4], data[i,5]], method='reverse')
    e = geocoder.google([data[i,6], data[i,7]], method='reverse')
    start.append(s.postal)
    end.append(e.postal)
    z_code[i,0] = s.postal
    z_code[i,1] = e.postal


zipcode = [start, end]

print(z_code)

here is the output I am getting ,

[[  0.   0.]
[ nan  nan]
[ nan  nan]
[ nan  nan]
[ nan  nan]
....
....
[ nan  nan]
[ nan  nan]
[ nan  nan]
[ nan  nan]
[ nan  nan]
[ nan  nan]]

output should be like this, these are the zipcodes that are been converted from latitude and longitude

[[     0.      0.]
[ 94105.  94103.]
[ 94133.  94108.]
[ 94133.  94133.]
[ 94114.  94122.]
[ 94104.  94128.]
[ 94128.  94066.]
......
......
[ 94128.  94066.]
[ 94118.  94116.]
[ 94109.  94102.]]

Please help, thank you in advance !


Solution

  • One possible reason is number of request you are sending to google api. you can can call google api only 2500 time a day.

    for further detail read: https://developers.google.com/maps/documentation/geocoding/usage-limits