这是数据集的示例
https://i.stack.imgur.com/YtESW.png
这是我想要实现的结果
https://i.stack.imgur.com/GnHpS.png
这是我的代码:
df.pivot( values = ['Image Name'],index=['sku','Name of product']).reset_index()
这是数据集
sku,Name of product,Image Name
155280,Catalinaresin planter in white H 100cm,Catalinaresin planter in white H 100cm.jpg
155280,Catalinaresin planter in white H 100cm,Catalinaresin planter in white H 100cm2.jpg
155280,Catalinaresin planter in white H 100cm,Catalinaresin planter in white H 100cm3.jpg
155280,Catalinaresin planter in white H 100cm,Catalinaresin planter in white H 100cm4.jpg
试试这个,
pd.pivot_table(data=df,index='sku',columns='Image Name',values='Name of product',aggfunc=lambda x: ' '.join(str(v) for v in x))