Pandas | Group by with all the values of the group as comma separated

前端 未结 1 1914

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 h

相关标签:
1条回答
  • 2021-02-15 14:06

    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
    
    0 讨论(0)
提交回复
热议问题