我有400,000个带有经度和纬度的案例。我想把这些转换为邮政编码。下面的代码可以工作...
import geopy
from geopy.geocoders import Nominatim
geolocator = geopy.Nominatim(user_agent='my-application')
def get_zipcode(df, geolocator, lat_field, lon_field):
location = geolocator.reverse((df[lat_field], df[lon_field]))
if 'address' in location.raw.keys():
if 'postcode' in location.raw['address'].keys():
return location.raw['address']['postcode']
else:
但只是在小批量的时候,但需要一段时间,比如2000箱需要15分钟。
dfbatch1['pickup_zip'] = dfbatch1.apply(get_zipcode, axis=1, geolocator=geolocator, lat_field='pickup_latitude', lon_field='pickup_longitude')
What would be the best way to convert all of my latitudes & longitudes to zip codes?