飞道的博客

Python碎片|腾讯位置大数据

331人阅读  评论(0)

import requests
import json
import pandas as pd
header={
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0'}
url = 'https://xingyun.map.qq.com/api/getXingyunPoints'
for i in range(1,5):
    payload = {'count': i, 'rank': 0}
    response = requests.post(url, data=json.dumps(payload))
    datas=json.loads(response.text)['locs']
    datas=datas.split(',')
    datas=[int(i) for i in datas[:-1]]
    all_data=[]
    a=[]
    for n,data in enumerate(datas):
        a.append(data)
        all_data.append(a)
        if (n+1)%3==0:
            a=[]
all_data=[[i[0]/100,i[1]/100,i[2]] for i in all_data]
# li={'dt':all_data}
df = pd.DataFrame(all_data)
# df.to_csv('./res.csv',encoding='gbk')
lat=[float(i[0]) for i in all_data]
long=[i[1] for i in all_data]
weight=[i[2] for i in all_data]
dataframe=pd.DataFrame({'纬度':lat,'经度':long,'人数':weight})
dataframe=dataframe.drop_duplicates(keep='first')
data1=dataframe[(dataframe.纬度.between(39.26,41.03)) & (dataframe.经度.between(115.25,117.30))]
import folium
from folium.plugins import HeatMap
map_data = data1[['纬度', '经度', '人数']].values.tolist()
hmap = folium.Map(
    location=[data1['纬度'].mean(), data1['经度'].mean()],  #地图中心坐标
    control_scale=True,
    zoom_start=13    #地图显示级别
)
hmap.add_child(HeatMap(map_data, radius=5, gradient={.1: 'blue',.3: 'lime', .5: 'yellow',.7:'red'}))
hmap.save('shool9.html')


转载:https://blog.csdn.net/wglink/article/details/112651460
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场