In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about how big data obtains the longitude and latitude information of the specified address in batches. The editor thinks it is very practical, so I share it with you. I hope you can learn something after reading this article. Let's take a look at it with the editor.
How to query address longitude and latitude information in batches?
Grab the bag
Open https://jingweidu.51240.com/
F12 key (mac computer shortcut option+command+I) opens the developer tools Network panel
Enter the query address in the search box and enter to query.
The developer tool Network will see the URL in the screenshot
Click Preview to see the specific information.
1. Longitude and latitude query crawler function query
1. According to the packet analysis, construct the URL template template
two。 Initiate access using the requests library
3. Using regular expression re library to parse longitude and latitude information
Import requestsdef query (addr): # query the latitude and longitude of addr template = 'https://apis.map.qq.com/jsapi?qt=geoc&addr={addr}&key=UGMBZ-CINWR-DDRW5-W52AK-D3ENK-ZEBRC&output=jsonp&pf=jsapi&ref=jsapi&cb=qq.maps._svcb2.geocoder0' url = template.format (addr=addr) resp = requests.get (url) x = re.findall (' pointx ":" (. *?) ",' Resp.text) [0] y = re.findall ('pointy ":" (. *?) ",', resp.text) [0] return XLING YQuery (addr=" Xing'an Street, Anqiu City, Weifang City, Shandong Province ") ('119.161423rd,' 36.331699')
two。 test data
Import pandas as pddf = pd.read_csv ("test.csv") df
Companyaddr0 Company An Anqiu City, Weifang City, Shandong Province Xingan Street Company 1 Company B Xiaoshan District, Hangzhou City, Zhejiang Province, Company 2 Company C Panyu District, Guangzhou City, Guangdong Province, Company 3 Company D Lianhu District, Xi'an City, Shaanxi Province
Df ['addr'] 0 Xingan Street, Anqiu City, Weifang City, Shandong Province 1 Xiaoshan District, Hangzhou City, Zhejiang Province 2 Panyu District, Guangzhou City, Guangdong Province 3 Name: addr, dtype: object, Lianhu District, Xi'an City, Shaanxi Province
3. Batch query
For the selected addr column, use the apply method to call the query function to query the longitude and latitude in batches
Df ['Latitude and Longitude'] = df ['addr'] .apply (query) df0 (119.161423, 36.331699) 1 (120.264570, 30.185340) 2 (113.384240, 22.937720) 3 (108.940200, 34.267030) Name: addr, dtype: object
4. Save
Df ['latitude and longitude'] = df ['addr'] .apply (query) df
Companyaddr Latitude and Longitude 0 Company An Anqiu City, Weifang City, Shandong Province Xingan Street (119.161423, 36.331699) 1 Company B Xiaoshan District, Hangzhou City, Zhejiang Province (120.264570, 30.185340) 2 Company C Panyu District, Guangzhou City, Guangdong Province (113.384240, 22.937720) 3 Company D Lianhu District, Xi'an City, Shaanxi Province (108.940200, 34.267030)
5. Export csv
The results are exported to csv
The above df.to_csv ('result.csv') is how big data obtains the longitude and latitude information of the specified address in batches. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.