1
I am trying to convert latitude and longitude data into python which are in the following format:
Latitude Longitude
27º59' N 86º55'E
This data was extracted from the following web page and converted into a csv file: http://www.peaklist.org/WWlists/WorldTop50.html
I made the code to convert but got the result as Nan. I tried several different ways and the last code I tried was the following:
data['Longitude'] = data['Longitude'].str.extract('°\'([N|S|E|W])', expand=True)
(parts[0].astype(int) + parts[1].astype(float) / 60) * parts[2].map({'N':1, 'S':-1, 'E': 1, 'W':-1})
The data in the latitude and longitude columns are in string format. Thank you
Try this regex
r"(\d{1,2})[º](\d{1,2}\.\d{1,2})*[']\s(\w)"
works for"37º45.3' E"
for example. But if you don’t have the.3
(in the example), you will have to modify the regex a little.– Paulo Marques