I need help doing the following.
I have a list of Latitude and Longitude values (so two columns; one called "lat", the other called "long" that I'd like to pass to a function in order to get zip codes (aka reverse geocoding). Where I'm getting stuck is in the for loop. Here's what I have so far:
from uszipcode import ZipcodeSearchEngine import pandas as pd import numpy as np search = ZipcodeSearchEngine() res = [] df = pd.read_csv('LATLONG.csv') for index, row in df.iterrows(): res = search.by_coordinate(row["lat"], row["long"], radius=2, returns=1) When I run the following in the terminal, it does not give me any results. I eventually have to stop the job.
If I run the script with actual numbers, it does work when I do the following:
for zipcode in res: print(zipcode.Zipcode) Overall, the idea is that I can pass all the latlong values from the dataframe and get an array/list of the zip codes for those values and export it back to a CSV file. Any help will be greatly appreciated.
search.by_coordinatework at all, for any coordinates? Isrow["lat"]in the format/encoding/scale/unit/whatever thatsearchwants?search.by_coordinatedoes work. I've tried it by hardcoding coordinates in my list. I just can't seem to get the for loop to work correctly. I have about 100k values in my list so I'm not sure if that's why it's taking long to run the script. This is an example of what it looks like when I hardcode it (straight from my csv file):search.by_coordinate(42.4049, -82.923, radius=2, returns=5)for zipcode in res: print(zipcode.Zipcode){"City": "Detroit", "Density": 7755.4973821989515, "HouseOfUnits": 19244, "LandArea": 5.73, "Latitude": 42.40752699999999, "Longitude": -82.9447782, "NEBoundLatitude": 42.436000899999996, "NEBoundLongitude": -82.9138969, "Population": 44439, "SWBoundLatitude": 42.38746889999999, "SWBoungLongitude": -82.96503589999998, "State": "MI", "TotalWages": 434255347.0, "WaterArea": 0.0, "Wealthy": 9771.94237044038, "Zipcode": "48224", "ZipcodeType": "Standard"} and this is where I pull the "Zipcode".forloop.