title: Ranking of multi-indexed DF
body: <p>I have a multi-indexed DF with the following structure:</p>
  
  <pre><code>&gt;&gt;&gt; df = pd.DataFrame({(2014, 'value'): {('AR', 0): 1.2420, ('AR', 1): 0.1802,('BR', 0): 1.3,('BR', 1): 0.18}})
  &gt;&gt;&gt; print df
  
        2014
        value
  AR 0  1.2420
     1  0.1802
  BR 0  1.3000
     1  0.1800
  </code></pre>
  
  <p>My goal is to add a column 'rank', that contains the ranking of the countries (AR &amp; BR) for 0 &amp; 1 in descending order. The desired result would be something like:</p>
  
  <pre><code>            2014          
              value   rank 
  iso   id
  AR    0     1.2420  2      
        1     0.1802  1    
  BR    0     1.3     1    
        1     0.18    2  
  </code></pre>
  
  <p>My initial approach was to reset the index:</p>
  
  <pre><code>&gt;&gt;&gt; df = df.reset_index()
  &gt;&gt;&gt; print df
  
         level_0   level_1   2014
                             value
  0      AR        0         1.2420
  1      AR        1         0.1802
  2      BR        0         1.3000
  3      BR        1         0.1800
  </code></pre>
  
  <p>And then add the 'rank' column using a groupby and rank:</p>
  
  <pre><code>&gt;&gt;&gt; df[2014, 'gr'] =  df.groupby(['level_1'])[2014, 'value'].rank(ascending=False)
  </code></pre>
  
  <p>This results, however, in:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/pandas/core/groupby.py", line 2990, in __getitem__
      if len(self.obj.columns.intersection(key)) != len(key):
    File "/usr/local/lib/python2.7/dist-packages/pandas/core/index.py", line 3774, in intersection
      result_names = self.names if self.names == other.names else None
  AttributeError: 'tuple' object has no attribute 'names'
  </code></pre>
  
  <p>Am I on the right track, another approach I should consider?</p>