1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Python读取SQLite数据库数据写入csv

Python读取SQLite数据库数据写入csv

时间:2024-06-09 08:12:32

相关推荐

Python读取SQLite数据库数据写入csv

import sqlite3import bd_gc_84import csvimport timestart =time.clock()print("正在运行..................")#新建csv文件file = open('dezhou.csv', 'w', encoding='utf-8', newline="")csv_writer = csv.writer(file)csv_writer.writerow(["x","y","count","cityId","date"])#打开数据库con = sqlite3.connect("E:\BaiDuMap\hydata.db") c = con.cursor()i = 0for row in c.execute("select * from heatmapdata where cityId = 372"):# if i >= 100000:#break# print(row)#百度墨卡托转百度经纬度bd09mcTobd09ll = bd_gc_84.mercatortobd09(row[0],row[1])# print(bd09mcTobd09ll)#百度经纬度转国测bd09togc = bd_gc_84.bd09togcj02(bd09mcTobd09ll[0],bd09mcTobd09ll[1])# print(bd09togc)#国测转84gcto84 = bd_gc_84.gcj02towgs84(bd09togc[0],bd09togc[1])# print(gcto84)#写入文件csv_writer.writerow([gcto84[0],gcto84[1],row[2],row[3],row[4]])i = i + 1#利用百度接口进行转换# url = "https://api./geoconv/v1/?coords=" + x + "," + y + "&from=6&to=3&ak=TAnwBKfyivSOa4iqeO6Gw6lRhNF3zKel"# print (url)#关闭文档file.close()print("运行结束!")#关闭数据库c.close()con.close()print("转换数据总量:" + str(i))end = time.clock()print("运行时间:" + "%.3f"%(end-start)+"秒")

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。