首页 > 解决方案 > 应用进度的反向地理编码

问题描述

我有一个包含一列纬度坐标和一列经度坐标的数据框,我试图用这两列作为参数调用 progress_apply 函数,因为我有一个大数据集并且需要使用 RateLimiter 包装器。我的问题是 progress_apply 很难识别数据框中的元组。这是我的代码:

geolocator = Nominatim(user_agent="user")
reverse = RateLimiter(geolocator.reverse, min_delay_seconds=0.1, max_retries=10)

data = pd.read_excel('file_path')
df = pd.DataFrame(data, columns = ['Column3','Column4','Column21','Column22','Column23'])
df.columns = ['status', 'class', 'year', 'latitude', 'longitude']
df['points'] = [(tuple['latitude'], tuple['longitude']) for i, tuple in df.iterrows()]

tqdm.pandas()
df['country'] = df['points'].progress_apply(lambda x: reverse(x).raw['address']['country'])

程序引发“ValueError:必须是坐标对或点”,但是当我检查 x 使用的是什么类型时,程序将其识别为元组。

任何帮助表示赞赏。此外,如果您知道从纬度和经度获取国家信息的更好方法,那也可以。

标签: pythonpandasgeopy

解决方案


推荐阅读