python - 应用进度的反向地理编码
问题描述
我有一个包含一列纬度坐标和一列经度坐标的数据框,我试图用这两列作为参数调用 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 使用的是什么类型时,程序将其识别为元组。
任何帮助表示赞赏。此外,如果您知道从纬度和经度获取国家信息的更好方法,那也可以。
解决方案
推荐阅读
- swift - 尝试使用 AVCapturePhotoOutput 捕获照片时图像变暗
- concatenation - 如何在顶点连接两个地图
- javascript - 是否可以将嵌套数组拆分为Js中的两个数组
- html - 如何隐藏/删除前一个 div 的背景图片
- lua - 更新openwrt web界面luci中的变量信息
- java - 串行蒸汽的性能、内部工作和执行顺序
- angular - 动态添加响应式元素会使它们在 Angular 中自动失效
- android - Android Studio 将新文件从 kotlin 移动到 java 包中
- ms-access - 如何以 Ms.Access 查询为条件选择 COUNT(DISTINCT) 和 WHERE
- python - 如何将一列添加到从 0 开始直到数组长度的 numpy 数组?