Skip to content Skip to sidebar Skip to footer

Pandas | Group By With All The Values Of The Group As Comma Separated

As per application requirement, I need to show all the data which is part of group by in comma separated format so the admin can take decision, I am new to Python and not sure how

Solution 1:

You can use:

In [35]: df.groupby('company').product.agg([('count', 'count'), ('product', ', '.join)])
Out[35]: 
           count          product
company                          
Amazon         1           E-comm
Facebook       1     Social Media
Google         2  Search, Android
Microsoft      2        OS, X-box

Post a Comment for "Pandas | Group By With All The Values Of The Group As Comma Separated"