Python调用高德API实现批量地址转经纬度并写入表格的功能
作者:spl.与我常在(live) 时间:2023-12-26 03:22:20
本段代码是先将需要转换经纬度的地址爬取在 ‘地址.csv' 文件里,文件截图示例:
代码展示
# coding=utf-8
# SPL
# 时间:2020/12/20 21:15
import csv
import requests
import json
import pandas as pd
num=0
y=[]
with open("地址.csv", 'r') as f: #写入将要转换的地址的文件路径,此处为默认文件路径(要先将文件提前导入)(注意是csv格式文件)
r = csv.reader(f, delimiter=',')
for row in r:
print(row[0])
#记得在key=后面填入申请百度地图开发平台的key
url = "http://restapi.amap.com/v3/geocode/geo?key=**********&address=" + row[0]
dat = {
'count': "1",
}
r = requests.post(url, data=json.dumps(dat))
s = r.json()
b = s['geocodes']
for j in range(0, 10000):
try:
neirong1 = b[j]
except:
continue
try:
b = neirong1['location']
except:
continue
try:
lon_lat= b.split(',')
lon=float(lon_lat[0])
lat = float(lon_lat[1])
print(lon)
print(lat)
except:
continue
num += 1
print("第" + str(num) + "条地址转换成功")
y.append([row[0], lon, lat])
result = pd.DataFrame(y)
result.columns = ['地址', '经度', '纬度']
result.to_csv('地址转经纬度.csv', encoding='utf-8-sig', index=False)
运行结果
转换成功后生成的表格截图 _
来源:https://blog.csdn.net/gjgfjgy/article/details/112443653
标签:Python,高德API,经纬度
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
微信企业号开发之微信考勤百度地图定位
2024-05-08 10:11:47
![](https://img.aspxhome.com/file/2023/9/129019_0s.jpg)
MySQL加密和解密实例详解
2024-01-16 01:57:38
![](https://img.aspxhome.com/file/2023/5/121565_0s.png)
Django-celery-beat动态添加周期性任务实现过程解析
2021-07-29 13:09:49
由Python运算π的值深入Python中科学计算的实现
2021-10-21 03:48:06
![](https://img.aspxhome.com/file/2023/0/78530_0s.png)
python实现字符串连接的三种方法及其效率、适用场景详解
2023-07-27 19:57:32
浅谈SQL Server 2016里TempDb的进步
2024-01-13 20:23:41
![](https://img.aspxhome.com/file/2023/6/113596_0s.png)
python中偏函数partial用法实例分析
2021-03-24 21:35:23
总结MySQL修改最大连接数的两个方式
2024-01-27 22:55:55
![](https://img.aspxhome.com/file/2023/4/69164_0s.jpg)
详解python调用cmd命令三种方法
2022-05-09 09:01:21
Python比较两个日期的两种方法详解
2023-12-25 03:52:17
![](https://img.aspxhome.com/file/2023/6/86396_0s.png)
golang gorm中格式化时间问题详解
2023-07-12 09:45:21
【JavaScript实用系列】-- 胖页面载入效果
2009-10-19 22:48:00
Python Asyncio中Coroutines,Tasks,Future可等待对象的关系及作用
2021-02-09 02:01:47
![](https://img.aspxhome.com/file/2023/0/131590_0s.png)
WPF自定义搜索框代码分享
2023-07-18 23:31:04
![](https://img.aspxhome.com/file/2023/1/79061_0s.jpg)
Python实现破解网站登录密码(带token验证)
2021-09-29 06:22:22
![](https://img.aspxhome.com/file/2023/1/82511_0s.jpg)
Python实现文字pdf转换图片pdf效果
2021-03-10 23:20:03
使用实现pandas读取csv文件指定的前几行
2021-06-28 12:05:26
浅谈解决360兼容模式浏览器的方法
2023-09-17 01:11:39
Python Excel处理库openpyxl详解
2021-10-18 13:59:04
MySQL事务的隔离级别详情
2024-01-27 23:33:56
![](https://img.aspxhome.com/file/2023/0/114030_0s.png)