I have Latitude and Longitude Columns in a dataframe like this:
Station Latitude Longitude
0 1 18° 23' 20.9 72° 23' 25.9
1 2 17° 22' 20.5 73° 22' 21.5
etc etc etc
With a space between the values. I want to convert the lat lon values to decimal (float)
I tried this code:
def dms2dd(s):
degrees, minutes, seconds = re.split('[°\'\ ]+', s)
dd = -1*float(degrees) -1*float(minutes)/60 -1*float(seconds)/(60*60);
return dd
df['LATITUDE'] = df['LATITUDE'].apply(dms2dd)
df['LONGITUDE'] = df['LONGITUDE'].apply(dms2dd)
But gets me an error:
ValueError: too many values to unpack (expected 3).
The Stations are in the south hemisphere (thats why i use (-) in the function).
Can you help me please?