title: Create new columns from aggregates of other columns in pandas
body: <p>I have the following dataframe:</p>
  
  <pre><code>   col1    col2  col3
  0   tom     2    cash
  1   tom     3    gas
  2   tom     5    online
  3   jerry   1    online
  4   jerry   4    online
  5   jerry   5    gas
  6   scooby  8    cash
  7   scooby  6    dogfood
  8   scooby  1    cheese
  </code></pre>
  
  <p>easily obtained with:</p>
  
  <pre><code>data = {'col1': ['tom', 'tom', 'tom', 'jerry', 'jerry', 'jerry', 'scooby', 'scooby', 'scooby'],
  'col2': [2,3,5,1,4,5,8,6,1],
  'col3':['cash', 'gas', 'online', 'online', 'online', 'gas', 'cash', 'dogfood', 'cheese']}
  
  pd.DataFrame(data)
  </code></pre>
  
  <p>How would one group the data by <code>col1</code>, then as extra columns, get specific aggregates for specified values of <code>col3</code>.</p>
  
  <p>As an example, say I want to group by <code>col1</code> and get the sum of the <code>gas</code>, <code>cash</code> and <code>online</code> fields for everyone in <code>col1</code>, like this.</p>
  
  <pre><code>col1    gas_sum    cash_sum    online_sum
  tom        3          2             5
  jerry      5          0             5
  scooby     0          8             0
  </code></pre>
  
  <p>I am relatively new to pandas and the only way I can think of to do this is with a for loop through all the data, as <code>groupby</code>'s purpose is more to give the sum/mean of columns like <code>col2</code> in my example.</p>
  
  <p>Any help appreciated. </p>