I have a dataframe df like these 3 first rows are these
City | Longitude | Latitude |
---|---|---|
Toluca | W099.6569 | N19.2925 |
Pune | E73.8562 | N18.5167 |
Bloemfontain | E026.216667 | S29.116667 |
For example Bloemfontain row should be like these at the end
City | Longitude | Latitude |
---|---|---|
Bloemfontain | -29.116667 | 26.216667 |
I used this code
pattern = r'(?P<d>[\d\.]+).*?(?P<m>[\d\.]+).*?(?P<s>[\d\.]+)'
dms = df['Latitude'].str.extract(pattern).astype(float)
df['LATITUDE'] = dms['d'] + dms['m'].div(60) + dms['s'].div(3600)
dms = df['Longitude'].str.extract(pattern).astype(float)
df['LONGITUDE'] = dms['d'] + dms['m'].div(60) + dms['s'].div(3600)
but got not the right longitude and latitude
print(type(df['Latitude']))
. Is it a string?type(df['Latitude'].str)
pattern
seems to be expecting the geographic coordinates in degrees, minutes and seconds but such inputs are not indicated anywhere in your question.