title: Pandas groupby concat ungrouped column into comma separated string
body: <p>I have the following example df:</p>
  
  <pre><code>        col1     col2    col3   doc_no
       0     a        x       f        0
       1     a        x       f        1
       2     b        x       g        2
       3     b        y       g        3
       4     c        x       t        3
       5     c        y       t        4
       6     a        x       f        5
       7     d        x       t        5
       8     d        x       t        6
  </code></pre>
  
  <p>I want to group by the first 3 columns (<code>col1</code>, <code>col2</code>, <code>col3</code>), concatenate the fourth column (<code>doc_no</code>) into a line of strings based on the groupings of the first 3 columns, as well as also generate a sorted count column of the 3 column grouping (<code>count</code>). Example desired output below (column order doesn't matter):</p>
  
  <pre><code>        col1     col2    col3   count      doc_no
       0     a        x       f       3     0, 1, 5
       1     d        x       t       2        5, 6
       2     b        x       g       1           2
       3     b        y       g       1           3
       4     c        x       t       1           3
       5     c        y       t       1           4
  </code></pre>
  
  <p>How would I go about doing this? I used the below line to get just the grouping and the count:</p>
  
  <pre><code>grouped_df = df.groupby(['col1','col2','col3']).size().reset_index(name='count')\
      .sort_values(['count'], ascending=False).reset_index()
  </code></pre>
  
  <p>But I'm not sure how to also get the concatenated <code>doc_no</code> column in the same code line.</p>