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
Post a Comment