python - 如何在反向编码期间将 lat、lon 值从 csv 文件放入 url
问题描述
我有一个与此类似的 URL:https ://nominatim.openstreetmap.org/reverse?format=xml&lat=17.978733&lon=79.14550876&zoom=14&addressdetails= 1 我想更改 csv 文件中的lat
和lon
值。
import csv
import requests
import xml.etree.ElementTree as ET
def loadxml():
# url of rss feed
url = 'https://nominatim.openstreetmap.org/reverse?format=xml&lat=25.6&lon=78.0176&zoom=14&addressdetails=1'
# creating HTTP response object from given url
resp = requests.get(url)
# saving the xml file
with open('ldn.xml', 'wb') as f:
f.write(resp.content)
loadxml()
这是一个命令,lat
lon
但我想要我的 csvlat
和lon
值。
解决方案
可以按如下方式创建新的 url:
def get_url(lat,lon):
return 'https://nominatim.openstreetmap.org/reverse?format=xml&lat='+str(lat)+'&lon='+str(lon)'&zoom=14&addressdetails=1
假设您的数据框被称为 df 并且包含纬度和经度的列分别具有名称 lat 和 lon ,如下所示:
for index, row in df.iterrows():
url = get_url(row[lat],row[lon])
resp = requests.get(url)
with open('ldn.xml', 'wb') as f:
f.write(resp.content)
希望这可以帮到你。
推荐阅读
- json - 在 rust 中转换 json,类似 pandas explode 和 lamda
- json - 在另一个powershell脚本文件中调用powershell脚本时如何使用嵌套引号
- flutter - 我收到错误:找不到正确的提供程序
在此设置小部件上方(已修复) - linux - 在 CentOS 7 上由 Terraform 或 Molecule 执行时,带有用户和密码的 git https 克隆非常慢
- scala - 在 Spark GraphX 中更新节点属性的最佳结构是什么?
- java - 如何在基于 Internet 时间的 Android 中获取日期?
- php - Laravel如何让程序在页面刷新后记住select的值
- c# - 由于没有“获取枚举器”,C# 对于每个语句都无法操作“列表”,我该如何修复此代码?
- javascript - 动态导入组件Vue
- sql-server - Pentaho/Kettle:与 MSSQL Express 相比,表输入停止在大约 255,000 行