title: pandas: sort by the order of appearance
body: <p>Suppose we have a dataframe:</p>
  
  <pre><code>df = pd.DataFrame(pd.np.zeros((15,10,)), dtype=int, \
      index=[['a']*5+['b']*5+['c']*5, list(range(15))])
  df.index.names=['index0', 'index1']
  pd.np.random.seed(0)
  for i, v in df.iterrows():
      v.loc[pd.np.random.randint(10)] = 1
  
  df
  
                 0  1  2  3  4  5  6  7  8  9
  index0 index1                              
  a      0       0  0  0  0  0  1  0  0  0  0
         1       1  0  0  0  0  0  0  0  0  0
         2       0  0  0  1  0  0  0  0  0  0
         3       0  0  0  1  0  0  0  0  0  0
         4       0  0  0  0  0  0  0  1  0  0
  b      5       0  0  0  0  0  0  0  0  0  1
         6       0  0  0  1  0  0  0  0  0  0
         7       0  0  0  0  0  1  0  0  0  0
         8       0  0  1  0  0  0  0  0  0  0
         9       0  0  0  0  1  0  0  0  0  0
  c      10      0  0  0  0  0  0  0  1  0  0
         11      0  0  0  0  0  0  1  0  0  0
         12      0  0  0  0  0  0  0  0  1  0
         13      0  0  0  0  0  0  0  0  1  0
         14      0  1  0  0  0  0  0  0  0  0
  </code></pre>
  
  <p>How to sort first the rows in the blocks a, b and c by the order of appearance of "1" and then sort also a, b and c?</p>
  
  <p>Expected output:</p>
  
  <pre><code>               0  1  2  3  4  5  6  7  8  9
  index0 index1                              
  a      1       1  0  0  0  0  0  0  0  0  0
         2       0  0  0  1  0  0  0  0  0  0
         3       0  0  0  1  0  0  0  0  0  0
         0       0  0  0  0  0  1  0  0  0  0
         4       0  0  0  0  0  0  0  1  0  0
  c      14      0  1  0  0  0  0  0  0  0  0
         11      0  0  0  0  0  0  1  0  0  0
         10      0  0  0  0  0  0  0  1  0  0
         12      0  0  0  0  0  0  0  0  1  0
         13      0  0  0  0  0  0  0  0  1  0
  b      8       0  0  1  0  0  0  0  0  0  0
         6       0  0  0  1  0  0  0  0  0  0
         9       0  0  0  0  1  0  0  0  0  0
         7       0  0  0  0  0  1  0  0  0  0
         5       0  0  0  0  0  0  0  0  0  1
  </code></pre>
  
  <p>Edit: The values can be other than "1", in reality these are different text values.</p>