dtoolkit.geoaccessor.dataframe.geocode#

dtoolkit.geoaccessor.dataframe.geocode(df: pd.DataFrame, /, address: Hashable = 'address', provider: str | geopy.geocoder = 'photon', min_delay_seconds: float = 0, max_retries: int = 2, error_wait_seconds: float = 5, **kwargs) gpd.GeoDataFrame[source]#

Geocode Series(string) and get a GeoDataFrame of the resulting points.

Parameters:
addressHashable

The name of the column to geocode.

Note

This parameter only works for DataFrame.

providerstr or geopy.geocoder, default “photon”

Specifies geocoding service to use. Default will use “photon”, see the Photon’s terms of service at: https://photon.komoot.io. Either the string name used by geopy (as specified in geopy.geocoders.SERVICE_TO_GEOCODER) or a geopy Geocoder instance (e.g., Photon) may be used. Some providers require additional arguments such as access keys, please see each geocoder’s specific parameters in geopy.geocoders.

min_delay_seconds, max_retries, error_wait_seconds

See the documentation for RateLimiter() for complete details on these arguments.

**kwargs

Additional keyword arguments to pass to the geocoder.

Returns:
GeoDataFrame
Raises:
ModuleNotFoundError

If don’t have module named ‘geopy’.

Examples

>>> import dtoolkit.geoaccessor
>>> import pandas as pd
>>> df = pd.DataFrame(
...     {
...         "address": [
...             "boston, ma",
...             "1600 pennsylvania ave. washington, dc",
...         ],
...     }
... )
>>> df
                                 address
0                             boston, ma
1  1600 pennsylvania ave. washington, dc
>>> df.geocode("address")
                                 address                    geometry
0                             boston, ma  POINT (-71.06051 42.35543)
1  1600 pennsylvania ave. washington, dc  POINT (-77.03655 38.89770)