简体   繁体   English

我正在尝试使用pandas旋转数据集

[英]I am trying to pivot a dataset with pandas

This is the sample of the dataset 这是数据集的样本

https://i.stack.imgur.com/YtESW.png https://i.stack.imgur.com/YtESW.png

This is the result i am trying to achieve 这就是我想要达到的结果

https://i.stack.imgur.com/GnHpS.png https://i.stack.imgur.com/GnHpS.png

Here is my code: 这是我的代码:

df.pivot( values = ['Image Name'],index=['sku','Name of product']).reset_index()

Here is the dataset 这是数据集

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用 Pandas 将 json 文件转为特定格式。 我想在某些列上旋转它 - I am trying to pivot a json file using pandas to be in a specific format. I want to pivot it on certain columns Pandas:Pivot 类型化数据集 - Pandas: Pivot a typed dataset pandas pivot 表问题 - 假设我是如何构建它的? - pandas pivot table issue - assuming it is how i am structuring it? 我正在使用LabelEncorder将数据集从String更改为Numeric - Using LabelEncorder i am trying to change the dataset from String to Numeric 尝试使用像Excel Pivot这样的Pandas Pivot - Trying to use pandas pivot like excel pivot 我正在尝试按日期索引数据集,我做错了什么? - I am trying to index dataset by date, what am i doing wrong? ModuleNotFoundError,我正在尝试安装 pandas 但我遇到了一些错误 - ModuleNotFoundError, i am trying to install pandas but i got some error 我正在尝试在 pandas dataframe 上使用 shift(),但它没有像我预期的那样工作 - I am trying to use shift() on pandas dataframe, but it is not working as I expect 我正在尝试根据 Pandas 中的多列对数据进行分类? - I am trying categorize data based on multiple column in pandas? 我正在尝试在Ubuntu 13.10上为Python3.3安装熊猫 - I am trying to install pandas for Python3.3 on Ubuntu 13.10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM