Applying a function to two columns of pandas dataframe to get two new columns
<p>I have a pandas data frame with columns <code>Longitude</code> and <code>Latitude</code>. I'd like to get <code>X</code> and <code>Y</code> from them. There is a function in <code>utm</code> called <code>from_latlon</code> that does this. It receives <code>Latitude</code> and <code>Longitude</code> and gives <code>[X,Y]</code>. Here's what I do:</p>

<pre class="lang-py prettyprint-override"><code>    def get_X(row):
        return utm.from_latlon(row['Latitude'], row['Longitude'])[0]

    def get_Y(row):
        return utm.from_latlon(row['Latitude'], row['Longitude'])[1] 

    df['X'] = df.apply(get_X, axis=1)
    df['Y'] = df.apply(get_Y, axis=1)
</code></pre>

<p>I'd like to define a function <code>get_XY</code> and apply <code>from_latlon</code> just one time to save time. I took a look at <a href="https://stackoverflow.com/questions/13331698/how-to-apply-a-function-to-two-columns-of-pandas-dataframe">here</a>, <a href="https://stackoverflow.com/questions/16353729/pandas-how-to-use-apply-function-to-multiple-columns">here</a> and <a href="https://stackoverflow.com/questions/19914937/applying-function-with-multiple-arguments-to-create-a-new-pandas-column">here</a> but I could not find a way to make two columns with one <code>apply</code> function. Thanks.</p>