title: Pandas: Keep Column, Count, Drop Duplicates
body: <p>I'm currently trying to drop duplicates according to two columns, but count the duplicates before they are dropped. I've managed to do this via </p>
  
  <p><code>df_interactions = df_interactions.groupby(['user_id','item_tag_ids']).size().reset_index() \
   .rename(columns={0:'interactions'})</code></p>
  
  <p>but this leaves me with </p>
  
  <pre><code>   user_id  item_tag_ids  interactions
  0      170            71             1
  1      170           325             1
  2      170           387             1
  3      170           474             1
  4      170           526             2
  </code></pre>
  
  <p>It does what I want with respect to counting, adding as a column and dropping the duplicates but how would I do this with retaining the original structure (plus a new column). Adding more to <code>groupby</code> changes its behaviour.</p>
  
  <p>Here is the original structure, I only want to group by IDs:</p>
  
  <pre><code>   user_id  item_tag_ids  item_timestamp
  0   406225          7271      1483229353
  1   406225          1183      1483229350
  2   406225          5930      1483229350
  3   406225          7162      1483229350
  4   406225          7271      1483229350
  </code></pre>
  
  <p>I would like to have the new <code>item_timestamp</code> field in the smaller dataframe to contain the first occurring timestamp for that combination.</p>