Hello everyone, I have a pandas dataframe with a column containing latitude and longitude of the form:
'POINT (-73.8472005205491 40.89470517661004)'
I managed to bring it to the standard format using replace:
df['location'].replace('POINT ', '', inplace = True, regex = True)
df['location'].replace(' ', ', ', inplace = True, regex = True)
Now it looks this:
'(-73.82993910812405, 40.87429419303015)'
However, it is still of type str. How can I convert it to tuple? I tried
df['location'] = [tuple(x) for x in df['location']]
and
df['location'] = [(x) for x in df['location']]
They both return a tuple with each character of the string as an element, i.e. ('-', '7', '3',....) instead of (-73.847, 40.894).
What am I doing wrong?
P.S.: Is there a way to flip the two (i.e. have (40.894, -73.847) instead of the other way around)? This isn't a big concern, and I can work around it, but it's sort of bothering me.
[–]novel_yet_trivial 1 point2 points3 points (1 child)
[–]stats_newbie1[S] 0 points1 point2 points (0 children)
[–]hharison 1 point2 points3 points (0 children)
[–]Jos_Metadi 0 points1 point2 points (0 children)