title: Pandas pivot table for multiple columns at once
body: <p>Let's say I have a DataFrame:</p>
  
  <pre><code>   nj  ptype  wd  wpt
  0   2      1   2    1
  1   3      2   1    2
  2   1      1   3    1
  3   2      2   3    3
  4   3      1   2    2
  </code></pre>
  
  <p>I would like to aggregate this data using <code>ptype</code> as the index like so:</p>
  
  <pre><code>             nj             wd            wpt
         1.0  2.0  3.0  1.0  2.0  3.0  1.0  2.0  3.0
  ptype    
      1    1    1    1    0    2    1    2    1    0
      2    0    1    1    1    0    1    0    1    1
  </code></pre>
  
  <p>You could build each one of the top level columns for the final value by creating a pivot table with <code>aggfunc='count'</code> and then concatenating them all, like so:</p>
  
  <pre><code>nj = df.pivot_table(index='ptype', columns='nj', aggfunc='count').ix[:, 'wd']
  wpt = df.pivot_table(index='ptype', columns='wpt', aggfunc='count').ix[:, 'wd']
  wd = df.pivot_table(index='ptype', columns='wd', aggfunc='count').ix[:, 'nj']
  out = pd.concat([nj, wd, wpt], axis=1, keys=['nj', 'wd', 'wpt']).fillna(0)
  out.columns.names = [None, None]
  print(out)
          nj             wd            wpt
           1    2    3    1    2    3    1    2    3
  ptype
  1      1.0  1.0  1.0  0.0  2.0  1.0  2.0  1.0  0.0
  2      0.0  1.0  1.0  1.0  0.0  1.0  0.0  1.0  1.0
  </code></pre>
  
  <p>But I really dislike this and it feels wrong. I would like to know if there is a way to do this in a simpler fashion preferably with a builtin method. Thanks in advance!</p>