title: How to transpose pandas dataframe to cross-tabulate dataframe keeping all values
body: <p>Let's suppose we have such dataframe:</p>
  
  <pre><code>df = pd.DataFrame({'key' : ['one', 'two', 'three', 'four'] * 3,
                     'col' : ['A', 'B', 'C'] * 4,
                     'val1' : np.random.randn(12),
                     'val2' : np.random.randn(12),
                     'val3' : np.random.randn(12)})
  </code></pre>
  
  <p><code>key + col</code> is unique key </p>
  
  <p><a href="https://i.stack.imgur.com/mk6j9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mk6j9.png" alt="dataframe"></a></p>
  
  <p>I want to make <code>col</code> values to become columns split or to  cross-tabulate on them and finally to looks something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/vw3Ar.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vw3Ar.png" alt="enter image description here"></a></p>
  
  <p>First naive approach <code>pd.crosstab(df.key,df.col)</code> didn't work here well:</p>
  
  <p><a href="https://i.stack.imgur.com/ByAs2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ByAs2.png" alt="enter image description here"></a></p>
  
  <p>This code <code>pd.crosstab(df.key,df.col,values = df[['val1', 'val2', 'val3']], aggfunc = np.max)</code> failed to run with <code>ValueError: Wrong number of items passed 3, placement implies 1</code></p>
  
  <p>How get it work?</p>