title: Pandas: sorting by integer notation value
body: <p>In this dataframe, column <code>key</code> values correspond to integer notation of each song key.</p>
  
  <pre><code>    df
                                                  track    key  
      0                                        Last Resort     4  
      1                                Casimir Pulaski Day     8  
      2                                         Glass Eyes     8   
      3                    Ohio - Live At Massey Hall 1971     7   
      4                               Ballad of a Thin Man    11  
      5                               Can You Forgive Her?    11   
      6                                     The Only Thing     3    
      7                        Goodbye Baby (Baby Goodbye)     4    
      8                                     Heart Of Stone     0   
      9                                               Ohio     0   
      10                                          the gate     2   
      11                                         Clampdown     2    
      12                                     Cry, Cry, Cry     4   
      13                          What's Happening Brother     8   
      14                                       Stupid Girl    11   
      15                          I Don't Wanna Play House     7   
      16           Inner City Blues (Make Me Wanna Holler)    11   
      17              The Lonesome Death of Hattie Carroll     4   
      18  Paint It, Black - (Original Single Mono Version)     5  
      19                                  Let Him Run Wild    11    
      20            Undercover (Of The Night) - Remastered     5    
      21                                  Between the Bars     7   
      22                              Like a Rolling Stone     0   
      23                                              Once     2   
      24                                    Pale Blue Eyes     5   
      25          The Way You Make Me Feel - 2012 Remaster     1   
      26                                            Jeremy     2   
      27                                   The Entertainer     7   
      28                                          Pressure     9   
      29   Play With Fire - Mono Version / Remastered 2002     2   
      30                                     D-I-V-O-R-C-E     9   
      31                                          Big Shot     0   
      32                                   What's Going On     1   
      33                        Folsom Prison Blues - Live     0   
      34                                    American Woman     1  
      35                              Cocaine Blues - Live     8   
      36                                       Jesus, etc.     5    
  </code></pre>
  
  <p>the notation is as follows:</p>
  
  <pre><code>'C' --&gt; 0
  'C#'--&gt; 1
  'D' --&gt; 2
  'Eb'--&gt; 3
  'E' --&gt; 4
  'F' --&gt; 5
  'F#'--&gt; 6
  'G' --&gt; 7
  'Ab'--&gt; 8
  'A' --&gt; 9
  'Bb'--&gt; 10
  'B' --&gt; 11
  </code></pre>
  
  <p>what is specific about this notation is that <code>11</code> is closer to <code>0</code> than <code>2</code>, for instance. </p>
  
  <p><strong>GOAL</strong>:</p>
  
  <p>given an <code>input_notation = 0</code>, I would like to sort according to closeness to key <code>0</code>, or <code>'C'</code>.</p>
  
  <p>you can get closest value by doing:</p>
  
  <pre><code>closest_key = (input_notation -1) % 12 
  </code></pre>
  
  <p>so I would like to sort according to this logic, <strong>having on top <code>input_notation</code> values</strong> and then closest matches, like so:</p>
  
  <pre><code>    8                                     Heart Of Stone     0   
      9                                               Ohio     0 
      22                              Like a Rolling Stone     0   
      31                                          Big Shot     0   
      33                        Folsom Prison Blues - Live     0  
     (...) 
  </code></pre>
  
  <p>I have tried:</p>
  
  <pre><code>v = df[['key']].values
  
  df = df.iloc[np.lexsort(np.abs(v - (input_notation - 1) %12 ).T)]
  </code></pre>
  
  <p>but this does not work..</p>
  
  <p>any clues?</p>