为什么Geolocate不给我正确的地址?
因此,我正在分析宾夕法尼亚州费城的地址的数据集。现在,为了使用这些,我想获得确切的经度和纬度,以便以后在地图上显示它们。
我已经获得了列的独特条目作为清单,并实施了一个循环,以使我具有经度和纬度,尽管这给了我每个城市,有时甚至是费城以外的城市的坐标。
这是我到目前为止所做的:
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="my_user_agent")
geocode = lambda query: geolocator.geocode("%s, Philadelphia PA" % query)
cities = list(philly["station_name"].unique())
for city in cities:
address = city
location = geolocator.geocode(address)
if(location != None):
philly["longitude"] = location.longitude
philly["latitude"] = location.latitude
philly["coordinates"] = list(zip(philly["latitude"], philly["longitude"]))
So I was analyzing a data set with addresses in Philadelphia, PA. Now, in order to make use of these, I wanted to get the exact longitude and latitude to later show them on a map.
I have gotten the unique entries of the column as a list and have implemented a loop to get me the longitude and latitude, though it's giving me the same coordinates for every city and sometimes even ones that are outside of Philadelphia.
Here's what I did so far:
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="my_user_agent")
geocode = lambda query: geolocator.geocode("%s, Philadelphia PA" % query)
cities = list(philly["station_name"].unique())
for city in cities:
address = city
location = geolocator.geocode(address)
if(location != None):
philly["longitude"] = location.longitude
philly["latitude"] = location.latitude
philly["coordinates"] = list(zip(philly["latitude"], philly["longitude"]))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“ Philly”是字典对象列表,则可以在列表上迭代并将位置属性添加到每个记录中。
输出:
如果使用Pandas DataFrame,则可以在数据框架中的每个记录上迭代,然后在其中设置纬度,经度和协调字段。
您可以执行这样的操作:
输出:
如果您有一个具有重复站名称的列表,则应缓存结果,以免重复地进行地理位置请求。
If "philly" is a list of dictionary objects then you can iterate over the list and add the location properties to each record.
Output:
If working with a Pandas dataframe then you can iterate over each record in the dataframe then set the latitude, longitude and coordinates fields in it.
You can do something like this:
Output:
If you have a list with duplicate station names then you should cache the results so you don't make duplicate geolocation requests.