title: Groupby gives me an additional level of indices
body: <p>I have a dataframe that contains rankings on a group level:</p>
  
  <pre><code>       foo  rank
  year            
  2000    10   340
  2000  7010   134
  2000  7000   135
  2000  6940    83
  2000  6840    82
  2000  6830    19
  2000  6820    81
  2000  6800   162
  2000  6765   161
  2000  7020   136
  </code></pre>
  
  <p>I wrote a function that clusters rankings by some arbitrary <code>n</code>. For <code>n=2</code>, that is equivalent for grouping the upper 50% of ranks together, and the lower 50%:</p>
  
  <pre><code>def createRankGroups(group, n):
      maxRank = group['rank'].max()
      group['group'] = np.nan
      for i in range(1, n + 1):
          upperRankBoundary = maxRank / n * i
          idx = (group['rank'] &lt;= upperRankBoundary) &amp; group.group.isnull()
          group.loc[idx, 'group'] = i
      return group['group']
  </code></pre>
  
  <p>The problem is that when I use <code>apply</code> to use this function, I get an unneeded level of indices back, which ruins the merging.</p>
  
  <pre><code>df['group'] = df.groupby(level=0).apply(lambda x: createRankGroups(x, 2))
  Exception: cannot handle a non-unique multi-index!
  </code></pre>
  
  <p>And this is why:</p>
  
  <pre><code>In[42]: df.groupby(level=0).apply(lambda x: createRankGroups(x, 2)).head()
  Out[42]: 
  year  year
  2000  2000    2
        2000    1
        2000    1
        2000    1
        2000    1
  </code></pre>
  
  <p>I thought that perhaps this was caused by indices being non-unique (since I was not passing along <code>foo</code>, so I tried that as well:</p>
  
  <pre><code>In[43]: df = df.reset_index().set_index(['year', 'foo'])
  In[44]: df.groupby(level=0).apply(lambda x: createRankGroups(x, 2)).head()
  Out[44]: 
  year  year  foo 
  2000  2000  10      2
              7010    1
              7000    1
              6940    1
              6840    1
  </code></pre>
  
  <p>Finally, also enforcing sorting on the index by <code>df.sort_index(level=0, inplace=True)</code> didnt solve the issue. What can I do?</p>