title: pandas - create new column based on duplicates
body: <p>I would like to combine records that have an identical id number. For example, suppose I have this DataFrame:</p>
  
  <pre><code>df=pd.DataFrame({'id': [1, 2, 2, 4], 'animal': ['dog', 'cat', 'bear', 'mouse']})
  
  # just rearranging the order a bit
  df=df[['id', 'animal', 'name']]
  
    id animal name
    1   dog   john
    2   cat   mary
    2   bear  mary
    4   mouse joe
  </code></pre>
  
  <p>What I'd like to end up with is a way to get the following:</p>
  
  <pre><code>id  name  animal  more_animals
   1  john   dog      NaN
   2  mary   cat      bear
   4  joe    mouse    NaN
  </code></pre>
  
  <p>I could use <code>df[df.duplicated('id', 'last')]</code> to find the duplicated rows, then loop through each duplicated id and add details to the new column but wondered if there was something a bit more elegant.</p>
  
  <p>Anything come to mind?</p>