我在Jupyter Notebook中有一个数据框,其中包含GPS坐标列表,使用from geopy.geocoders import Nominatim
和import pandas as pd
。
stop_id Lat Long
0 2 53.352280 -6.263668
1 3 53.352345 -6.263758
2 4 53.352604 -6.264143
3 6 53.352783 -6.264417
4 7 53.352867 -6.264543
5 8 53.353287 -6.265152
我一直在尝试添加一个新的列,将GPS坐标对应的地址填充到该列中。
为了实现这个目标,我尝试了以下方法:
df['address'] = geolocator.reverse((df['Lat'], df['Long']))
但是收到了以下错误信息:
ValueError: 必须是坐标对或点。
然后我创建了另一个列[LatLong]。
df['LatLong'] = df[df.columns[1:]].apply(
lambda x: ', '.join(x.dropna().astype(float).astype(str)),axis=1)
stop_id Lat Long LatLong
0 2 53.352280 -6.263668 53.35228, -6.263668
1 3 53.352345 -6.263758 53.352345, -6.263758
2 4 53.352604 -6.264143 53.352604, -6.264143
3 6 53.352783 -6.264417 53.352783, -6.264417
4 7 53.352867 -6.264543 53.352867, -6.264543
5 8 53.353287 -6.265152 53.353287, -6.265152
我随后运行了以下代码:
df['address'] = geolocator.reverse(df['LatLong'])
然而,我只得到了完全相同的错误信息。
我使用的代码是从本网站上类似问题的其他答案和GeoPy文档中适应的,因此我认为我的代码不够精确,无法正确地提取GPS坐标。
有人能指出我的错误吗?