python - questions on pandas group by functionality? -


i have following data set:

productid att 12        block10 12        block20 12        clean 12        screw 12        nail 13        hard 13        cover 14        round 14        narrow 14        black 15        block4 

i wanted group dataframe according product id , following result:

productid att 12        block10 block20 clean screw nail 13        hard cover 14        round narrow black 15        block4 

i can use pandas.groupby('productid') group data not sure how write data specific productid single row separated space.

groupby on 'productid' , apply join:

in [6]: df.groupby('productid')['att'].apply(' '.join)  out[6]: productid 12    block10 block20 clean screw nail 13                          hard cover 14                  round narrow black 15                              block4 name: att, dtype: object 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -