Pandas groupby multiple columns, list of multiple columns

前端 未结 4 879
庸人自扰
庸人自扰 2020-12-25 08:22

I have the following data:

Invoice NoStockCode Description                         Quantity    CustomerID  Country
536365  85123A      WHITE HANGING HEART T-         


        
4条回答
  •  囚心锁ツ
    2020-12-25 08:55

    IIUC

    df.groupby(['Invoice','CustomerID'],as_index=False)['Description','NoStockCode'].agg(','.join)
    Out[47]: 
       Invoice  CustomerID                                        Description  \
    0   536365       17850  WHITEHANGINGHEARTT-LIGHTHOLDER,WHITEMETALANTER...   
               NoStockCode  
    0  85123A,71053,84406B  
    

提交回复
热议问题