首页 > 代码库 > python_广州房价热力图

python_广州房价热力图

 

调用百度地图api,获取经纬度数据,然后在调用百度地图api,生成热力图

import pandas as pd
import numpy as np
data = pd.read_excel(rD:\\新的安居客数据 (恢复的).xlsx)

import requests
import json
import time
def get_long(weizhi):
    url="http://restapi.amap.com/v3/geocode/geo?address={}&output=json&key=***********4b0e539e&city=%E5%B9%BF%E5%B7%9E".format(weizhi)
    try:
        res=requests.get(url)
        data=json.loads(res.text)
        loca=data["geocodes"][0]["location"].split(",")[0]
        return loca
    except:
        pass
        return None
def get_lat(weizhi):
    url="http://restapi.amap.com/v3/geocode/geo?address={}&output=json&key=*****994b0e539e&city=%E5%B9%BF%E5%B7%9E".format(weizhi)
    try:
        res=requests.get(url)

        data=json.loads(res.text)
        loca=data["geocodes"][0]["location"].split(",")[1]
        return loca
    except:
        pass
        return None
data["lat"]=data["楼盘名称"].apply(get_lat)
data["lng"]=data["楼盘名称"].apply(get_long)
new_data.to_csv(r"D:\\new_datass.csv")
b=[]
with open(r"D:\\new_datass.csv") as f:
    a=f.readlines()
    print(a)
    for item in a:
        a=item.strip("\n").split(",")
        data=[a[2],a[1]]
        dic={a[0]:data}
        b.append(dic)
        

 

python_广州房价热力图