Apr-15-2017, 06:23 PM
For me it works quite well.
Output:In [4]: a = '"{u\'type\': u\'Point\', u\'coordinates\': [43.18040111, -79.02213645]}"'
In [5]: df = pd.DataFrame({"geo":[eval(a)]})
In [6]: df
Out[6]:
geo
0 {u'type': u'Point', u'coordinates': [43.180401...
In [7]: repr(df.geo[0])
Out[7]: '"{u\'type\': u\'Point\', u\'coordinates\': [43.18040111, -79.02213645]}"'
In [8]: pattern = r".*\[(-*\d+\.\d+), (-*\d+\.\d+)\].*"
In [9]: df['long'] = np.float(df.geo.str.replace(pattern, r"\1"))
In [10]: df
Out[10]:
geo long
0 {u'type': u'Point', u'coordinates': [43.180401... 43.180401
It looks that your string is actually representation of geo dictionary, it would be easier if you extracted long/lat from dictionary before converting it to a string.