title: Pandas: sort multiple columns based on some rules for possible values
body: <p>I have a dataframe like the following:</p>
  
  <pre><code>import pandas as pd
  df = pd.DataFrame([ ['X', 1],
                      ['a', 3],        
                      ['b', 4],
                      ['Y', 1],
                      ['Y', 4] ],
                      columns=['col1', 'col2' ]
                     )
  
  df
    col1 col2
  0    X   1
  1    a   3
  2    b   4
  3    Y   1
  4    Y   4
  </code></pre>
  
  <p>I would like to create a sorting rule that first sorts by col2, and then sorts by col1 based on a rule such that X should come first, then Y, and the rest can be alphabetical. None of the values are gauranteed to be in the dataframe, but if they are, I would like to sort as described. Desired result would be:</p>
  
  <pre><code>df
    col1 col3
  0    X   1
  1    Y   1
  2    a   3
  3    Y   4
  4    b   4
  </code></pre>
  
  <p>I know I can sort by a special order if I know all the values in the column, using Categorical like so:</p>
  
  <pre><code>df.col1=pd.Categorical(df.col1,['X','Y','a', 'b'])
  df.sort_values(['col2','col1'])
  </code></pre>
  
  <p>But I don't know what values will be present in col1. Was considering making a list in python from the col1 values, and sorting that list using some logic and then passing that sorted list to Categorical, but I'm wondering if there's a cleaner way perhaps just using pandas?</p>
  
  <p>Thanks in advance.</p>