title: Pandas Multiindex Groupby on Columns
body: <p>Is there anyway to use groupby on the columns in a Multiindex. I know you can on the rows and there is good <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html#groupby-with-multiindex" rel="noreferrer">documentation</a> in that regard. However I cannot seem to groupby on columns. The only solution I have is transposing the dataframe.</p>
  
  <pre><code>#generate data (copied from pandas example)
  arrays=[['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
  tuples = list(zip(*arrays))
  index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
  df = pd.DataFrame(np.random.randn(3, 8), index=['A', 'B', 'C'], columns=index)
  </code></pre>
  
  <p>Now I will try to groupby columns which fails</p>
  
  <pre><code>df.groupby(level=1)
  df.groupby(level='first')
  </code></pre>
  
  <p>However transposing with rows works</p>
  
  <pre><code>df.T.groupby(level=1)
  df.T.groupby(level='first')
  </code></pre>
  
  <p>So is there a way to do this without transposing?</p>