Removing round brackets from a dataframe of lat/lon pairs
<p>I'm sure this is a very simple thing to do but I seem to be having trouble! (I am rather new to this too.)</p>

<p>I have a dataframe containing lat long coordinates:</p>

<pre><code>    LatLon
0   (49.766795012580374, -7.556440128791576)
1   (49.766843444728075, -7.556439417755133)
2   (49.766843444728075, -7.556439417755133)
</code></pre>

<p>I would like to remove the round brackets/parentheses, but I just cannot work it out.</p>

<p>I keep getting errors like</p>

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

<p>But I'm not sure what to do to fix it.</p>

<p>I think it is because the type is object - so I need to convert it to string first? </p>

<p>If I do <code>.info()</code>:</p>

<pre><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></pre>

<p>and <code>df.dtypes</code>:</p>

<pre><code>LatLon    object
dtype: object
</code></pre>

<p>With the updated question, here is the updated answer.</p>

<p>Suppose we have this list of tuples:</p>

<pre><code>&gt;&gt;&gt; li
[(49.766795012580374, -7.556440128791576), (49.766843444728075, -7.556439417755133), (49.766843444728075, -7.556439417755133)]
</code></pre>

<p>We can create a data frame (which, fundamentally is a matrix or a list of lists) directly:</p>

<pre><code>&gt;&gt;&gt; df1=pd.DataFrame(li)
&gt;&gt;&gt; df1
           0         1
0  49.766795 -7.556440
1  49.766843 -7.556439
2  49.766843 -7.556439
&gt;&gt;&gt; df1.info()
&lt;class 'pandas.core.frame.DataFrame'&gt;
Int64Index: 3 entries, 0 to 2
Data columns (total 2 columns):
0    3 non-null float64
1    3 non-null float64
dtypes: float64(2)
memory usage: 72.0 bytes
</code></pre>

<p>Notice this is a 2 column data frame of floats. </p>

<p>However, imagine now we have this list, which is a list of lists of tuples:</p>

<pre><code>&gt;&gt;&gt; li2
[[(49.766795012580374, -7.556440128791576)], [(49.766843444728075, -7.556439417755133)], [(49.766843444728075, -7.556439417755133)]]
</code></pre>

<p>If you create a data frame here, you get what you have in the example:</p>

<pre><code>&gt;&gt;&gt; df2=pd.DataFrame(li2)
&gt;&gt;&gt; df2
                                 0
0  (49.7667950126, -7.55644012879)
1  (49.7668434447, -7.55643941776)
2  (49.7668434447, -7.55643941776)
&gt;&gt;&gt; df2.info()
&lt;class 'pandas.core.frame.DataFrame'&gt;
Int64Index: 3 entries, 0 to 2
Data columns (total 1 columns):
0    3 non-null object
dtypes: object(1)
</code></pre>

<p>Which is a one column data frame of tuples. </p>

<p>So I am guessing your issue is in the initial creation of you data frame. Instead of a list of lists or a list of tuples, your original data has a list of lists of tuples (or a list of tuples of tuples, etc)...</p>

<p>The fix (if I am correct) is to flatten the source list by one level:</p>

<pre><code>&gt;&gt;&gt; pd.DataFrame(t for sl in li2 for t in sl)
           0         1
0  49.766795 -7.556440
1  49.766843 -7.556439
2  49.766843 -7.556439
</code></pre>

python pandas dataframe