In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the methods of converting geographic longitude and latitude data with Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In mathematics, degrees, minutes and seconds that represent angles are represented by symbols such as °,', "and so on. The hexadecimal system is adopted between degrees and minutes, minutes and seconds, and their conversion relations are as follows:
1 °= 60'1 °= 3600 "1 °60"
Next, we use the data provided by the group to complete the operation of "degree, minute and second" data to "degree". The data screenshot is as follows.
When I got this requirement, I casually wrote down two solutions. But in the end, under the revision and improvement of the group friend Xiao Xiaoming (known as "Ming guy"), four solutions were provided.
① method 1: the apply () function import re of series
Import pandas as pd
Df = pd.read_csv ("t.txt", index_col=0)
Df.columns = ["latitude and longitude data"]
Def func (s):
Arr = re.findall ("\ d +", s)
Return int (arr [0]) + int (arr [1]) / 60+int (arr [2]) / 3600
Df ["final"] = df ["longitude and latitude data"] .apply (func)
Df
② method 2: split () method import re of str attribute in series
Import pandas as pd
Df = pd.read_csv ("t.txt", index_col=0)
Df.columns = ["latitude and longitude data"]
Tmp = df ["longitude and latitude data"] .str.split ("°|'|", expand=True) .values [:,: 3] .astype (int)
Df ["final"] = tmp [:, 0] + tmp [:, 1] / 60 + tmp [:, 2] / 3600
Df
③ method 3: extract () method import re of str attribute in series
Import pandas as pd
Df = pd.read_csv ("t.txt", index_col=0)
Df.columns = ["latitude and longitude data"]
Tmp = df ["longitude and latitude data"] .str.extract ("(\ d +) °(\ d +)'(\ d +)") .values.astype (int)
Df ["final"] = tmp [:, 0] + tmp [:, 1] / 60 + tmp [:, 2] / 3600
Df
④ method four: extractall () method import re of str attribute in series
Import pandas as pd
Df = pd.read_csv ("t.txt", index_col=0)
Df.columns = ["latitude and longitude data"]
Tmp = df ["longitude and latitude data"] .str.extractall ("(\ d +)") .unstack () .values.astype (int)
Df ["final"] = tmp [:, 0] + tmp [:, 1] / 60 + tmp [:, 2] / 3600
Df
This is the end of the content of "what are the methods of converting geographic longitude and latitude data with Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.