Adding Lat Lon coordinates to separate columns (python/dataframe)
<p>I'm sure this is a simple thing to do but I am new to Python and cannot work it out!</p>

<p>I have a data frame with one column containing coordinates and I am wanting to remove the brackets and add the Lat/Lon values into separate columns.</p>

<p>Current dataframe:</p>

<pre><code>gridReference
(56.37769816725615, -4.325049868061924) 
(56.37769816725615, -4.325049868061924) 
(51.749167440074324, -4.963575226888083)   
</code></pre>

<p>wanted dataframe:</p>

<pre><code>Latitude               Longitude
56.37769816725615     -4.325049868061924
56.37769816725615     -4.325049868061924
51.749167440074324    -4.963575226888083 
</code></pre>

<p>Thanks for your help</p>

<p>EDIT:
I have tried:</p>

<p><code>df['lat'], df['lon'] = df.gridReference.str.strip(')').str.strip('(').str.split(', ').values.tolist()</code></p>

<p>but I get the error:</p>

<p><code>AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas</code></p>

<p>I then tried adding:</p>

<p><code>df['gridReference'] = df['gridReference'].astype('str')</code></p>

<p>and got the error:</p>

<p><code>ValueError: too many values to unpack (expected 2)</code></p>

<p>Any help would be appreciated as I am not sure how to make this work! :)</p>

<p><strong>EDIT:</strong>
I keep getting the error 
<code>AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas</code></p>

<p>the output for df.dtypes is:</p>

<p><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
Int64Index: 22899 entries, 0 to 22898
Data columns (total 1 columns):
LatLon    22899 non-null object
dtypes: object(1)</code></p>

<p>the output for df.info() is:</p>

<p><code>gridReference  object
dtype: object</code></p>

<pre><code>df['gridReference'].str.strip('()')                               \
                   .str.split(', ', expand=True)                   \
                   .rename(columns={0:'Latitude', 1:'Longitude'}) 

             Latitude           Longitude
0   56.37769816725615  -4.325049868061924
1   56.37769816725615  -4.325049868061924
2  51.749167440074324  -4.963575226888083
</code></pre>

python pandas dataframe