Use dataframe column as arguments in function - iPython
<p>I am new with python and any help would be appreciated!</p>

<p>I have a dataframe with one column with coordinates:</p>

<pre><code>gridReference
(190000, 200000)
(560000, 250000)
(560000, 250000)
(560000, 250000)
(560000, 250000)
(560000, 250000)
(320000, 80000)
</code></pre>

<p>I also have a function which converts the coordinates to lat long positions 
<code>toConvert(E,N)</code> - I am trying to work out how to iterate through the gridReference column and input the values into the toConvert function as arguments then produce the new Lat-Lon coordinates in another dataframe.</p>

<p>Hope that makes sense - Thanks in advance!</p>

<p>To answer directly to your question you can do </p>

<pre><code>f = lambda x: toConvert(x[0],x[1])    
df['gridReference'].map(f)
</code></pre>

<p>But actually why do you need a Pandas DataFrame for that? You can just do the same with list of tuples or with tuple of tuples and performance should be the same. 
I believe a column made of tuples is of type object and is not handled by Numpy. Moreorever, your function is not vectorized. You could probably vectorize it using numba (see <a href="http://pandas.pydata.org/pandas-docs/stable/enhancingperf.html#vectorize" rel="nofollow">link</a>). </p>

<p>So you can achieve the same without pandas by using <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow">built-in function map</a> like so:</p>

<pre><code>map(df['gridReference'].values, f)
</code></pre>

python pandas dataframe