title: Pandas groupby result into multiple columns
body: <p>I have a dataframe in which I'm looking to group and then partition the values within a group into multiple columns.</p>
  
  <p>For example: say I have the following dataframe:</p>
  
  <pre><code>&gt;&gt;&gt; import pandas as pd
  &gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; df=pd.DataFrame()
  &gt;&gt;&gt; df['Group']=['A','C','B','A','C','C']
  &gt;&gt;&gt; df['ID']=[1,2,3,4,5,6]
  &gt;&gt;&gt; df['Value']=np.random.randint(1,100,6)
  &gt;&gt;&gt; df
    Group  ID  Value
  0     A   1     66
  1     C   2      2
  2     B   3     98
  3     A   4     90
  4     C   5     85
  5     C   6     38
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I want to groupby the "Group" field, get the sum of the "Value" field, and get new fields, each of which holds the ID values of the group. </p>
  
  <p>Currently I am able to do this as follows, but I am looking for a cleaner methodology:</p>
  
  <p>First, I create a dataframe with a list of the IDs in each group.</p>
  
  <pre><code>&gt;&gt;&gt; g=df.groupby('Group')
  &gt;&gt;&gt; result=g.agg({'Value':np.sum, 'ID':lambda x:x.tolist()})
  &gt;&gt;&gt; result
                ID  Value
  Group                  
  A         [1, 4]     98
  B            [3]     76
  C      [2, 5, 6]    204
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>And then I use pd.Series to split those up into columns, rename them, and then join it back.</p>
  
  <pre><code>&gt;&gt;&gt; id_df=result.ID.apply(lambda x:pd.Series(x))
  &gt;&gt;&gt; id_cols=['ID'+str(x) for x in range(1,len(id_df.columns)+1)]
  &gt;&gt;&gt; id_df.columns=id_cols
  &gt;&gt;&gt; 
  &gt;&gt;&gt; result.join(id_df)[id_cols+['Value']]
         ID1  ID2  ID3  Value
  Group                      
  A        1    4  NaN     98
  B        3  NaN  NaN     76
  C        2    5    6    204
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>Is there a way to do this without first having to create the list of values?</p>