Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python and users' actual geographical location to make personnel flow map in any area

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

The main content of this article is to explain "how to use Python and the actual geographical location of users to do any area personnel flow map", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn how to use Python and the actual geographical location of users to do any area personnel flow map!

First, data acquisition

Tencent actually opens the data interface, but it can only be used for commercial use:

After analysis, it is found that 4 post requests will be sent for each request, and the parameters of each request are as follows:

When the rank value changes from 1 to 4, we don't know what it means, so we just climb it all, and we can't do it again.

The returned data is as follows:

It is mainly the locs field. Take the first group of data as an example, 3295 represents latitude information, 11590 represents longitude information, divided by 11590 is both the original longitude and latitude value, 6 represents the number of people in this position.

Let's start writing code to get the data:

Import requestsimport jsonheader= {'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 rank': 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 nrecoveri data in enumerate (datas): a.append (data) all_data.append (a) if (n = 1)% 3 all_data= 0: a = [] all_data= [[I [0] / 100le I [1] / 100le I [2]] for i in all_data]

Convert the data to DataFrame format:

Import pandas as pdlat= [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 ({'latitude': lat,' longitude': number of long,'': weight})

Deduplicates the data:

Dataframe=dataframe.drop_duplicates (keep='first')

With these coordinate information, we can estimate the number of people in an area.

Pandas Little knowledge: DataFrame.drop_duplicates (subset=None, keep='first', inplace=False)

Subset is used to specify specific columns, default to all columns

Keep= "first" means to delete duplicates and retain the items that appear for the first time. In addition, the keepvalue can also be used for 'last':' to retain the last occurrence value; 'false':' means that all the same data is deleted

Selected area: data1=dataframe [(dataframe. Latitude. Between (39.26dJ 41.03) & (dataframe. Folium: import foliumfrom folium.plugins import HeatMapmap_data = data1 [['latitude', 'longitude', 'number of people]] .values.tolist () hmap = folium.Map (location= [data1 [latitude] .mean (), data1 [' longitude] .mean ()], # map center coordinate control_scale=True Zoom_start=13 # Map display level) hmap.add_child (HeatMap (map_data, radius=5, gradient= {. 1: 'blue',.3:' lime',. 5: 'yellow',.7:'red'}))

At this point, I believe you have a deeper understanding of "how to use Python and the actual geographical location of users to do personnel flow map in any region". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report