In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use Python instead of Mapinfo to find the nearest point in the two tables more quickly. I think it's very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
I. Preface
Work sometimes need to A table latitude and longitude points, from the B table to match the nearest point, with Mapinfo can also be achieved, but the processing speed is slow, especially when a large amount of data can not be processed at all, at this time with Python can be easily achieved, but also can show the processing progress, details are as follows.
II. Project objectives
Use Python to calculate the nearest point between two tables.
III. Project preparation
Software: PyCharm
Required libraries: pandas, xlrd,os
4. Project analysis 1) how to select and read the Excel file to be processed?
Using os and xlrd, select the Excel file that you want to read and process.
2) how to calculate the distance between two latitude and longitude points?
Use the pandas library to read the contents of two tables, and then define a function to calculate the distance between the two longitude and latitude points.
3) how to cycle through and save the data of the nearest point?
For loop is used to read the contents of the two tables, and the nearest distance point data is retained by If judgment.
4) how to save the results?
Save with to_excel to get the data of the nearest point.
5. Project implementation 1. The first step is to import the required library import pandas as pd import xlrd import os2, and the second step is to select and read the Excel file path= "D:/a/" # to get all the EXCEL names bb = path + 'result.xlsx' writer = pd.ExcelWriter (bb) under the folder. Engine='openpyxl') xlsx_names = [x for x in os.listdir (path) if x.endswith (".xlsx")] # get the first EXCEL name xlsx_names1 = xlsx_names [0] aa = path + xlsx_names1 # Open the first EXCEL first_file_fh=xlrd.open_workbook (aa) # get the SHEET name first_file_sheet=first_file_fh.sheets () 3, The third step is to cycle through and save the data of the nearest point for i in range (H2): w1=df1.loc [I 'latitude'] J1 = df1.loc [iJing 'longitude'] D1 = df1.loc [I,:] d0x1000000000000000000000000000.0000 print ("% d of the original community." % test_dict = {'distance': [d0]} d3 = pd.DataFrame (test_dict) for l in range (h3): w2=df2.loc [Latitude'] j2=df2.loc [Latitude'] d=haversine (J1, W1, j2, w2) if d
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.