-1

I have a table that has 10,000 address entries. I would like to obtain the full address from it and the state.

How could I do it with geopy module? Other modules such as geopandas are not available.

Example

address
------------------------------------------------------------------------------
Prosperity Drive Northwest, Huntsville, Alabama, United States 
------------------------------------------------------------------------------
Eureka Drive, Fremont, Newark, Alameda County, 94538, United States
------------------------------------------------------------------------------
Messenger Loop NW, Facebook Data Center, Los Lunas, Valencia County, New Mexico

Desired

address with format | state
----------------------------------------------------------------------------------------------
Prosperity Drive Northwest, Huntsville, Madison County, Alabama, 35773, United States | Alabama
----------------------------------------------------------------------------------------------
Eureka Drive, Fremont, Newark, Alameda County, California, 94538, United States | California
----------------------------------------------------------------------------------------------
Messenger Loop NW, Facebook Data Center, Los Lunas, Valencia County, New Mexico, 87031, United States | New Mexico

Thank you for your time.

Note

I am aware of how to use the Nominatim function and the extra module that can cope with pandas dataframe. But extra module is not available in this case.

June
  • 335
  • 4
  • 15

1 Answers1

0
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.geocode("Eureka Drive, Fremont, Newark, Alameda County, 94538, United States")
print(location.address)

Output:

Eureka Drive, Fremont, Newark, Alameda County, California, 94538, United States

Exactly as it's used in the documentation...

BeRT2me
  • 12,699
  • 2
  • 13
  • 31
  • If you want better results, use one of the paid service options. – BeRT2me May 11 '22 at 04:04
  • Thank you for your quick response. 1) As I mention in the first sentence, I have a table that has 10,000 address entries. If I use this function `geocode` repeatedly, it will throw a time out error. I write a loop and put `time.sleep` for it. But it still won't work for large table. 2) I need the state information. The `nominatim` function does not give a consistent format (it is either the third to the last or the second to the last element in the array) – June May 11 '22 at 05:30
  • 1
    GeoPy is designed to geocode, not parse into components. One of the paid options may give more consistently formatted results, or you'll have to use a separate library to try and parse address elements by type. You can't make a tool do something it's not designed to do. – BeRT2me May 11 '22 at 05:52