DataFrame sorting based on a function of multiple column values
<p>Based on <a href="https://stackoverflow.com/questions/24988873/python-sort-descending-dataframe-with-pandas">python, sort descending dataframe with pandas</a>:</p>

<p>Given:</p>

<pre><code>from pandas import DataFrame
import pandas as pd

d = {'x':[2,3,1,4,5],
     'y':[5,4,3,2,1],
     'letter':['a','a','b','b','c']}

df = DataFrame(d)
</code></pre>

<p>df then looks like this:</p>

<pre><code>df:
      letter    x    y
    0      a    2    5
    1      a    3    4
    2      b    1    3
    3      b    4    2
    4      c    5    1
</code></pre>

<p>I would like to have something like:</p>

<pre><code>f = lambda x,y: x**2 + y**2
test = df.sort(f('x', 'y'))
</code></pre>

<p>This should order the complete dataframe with respect to the sum of the squared values of column 'x' and 'y' and give me:</p>

<pre><code>test:
      letter    x    y
    2      b    1    3
    3      b    4    2
    1      a    3    4
    4      c    5    1
    0      a    2    5
</code></pre>

<p>Ascending or descending order does not matter. Is there a nice and simple way to do that? I could not yet find a solution.</p>