我需要使用现有列创建列作为字典。 df:
Period Category Sub-Category
FY18Q1 Footwear Shoes
FY18Q2 Footwear Sandal
FY18Q1 Footwear Shoes
FY18Q3 Footwear Boots
FY18Q1 Clothing Shirt
FY18Q2 Clothing Trouser
FY18Q1 Clothing Shirt
FY18Q3 Clothing Shirt
我想创建一个基于类别级别的两个新列。 A.类别级别上的子类别计数。 B.基于最近期间的子类别
Period Category Sub-Category freq Latest_freq
FY18Q1 Footwear Shoes {shoes:2,Sandal:1,Boots:1} Boots(FY18Q3)
FY18Q2 Footwear Sandal {shoes:2,Sandal:1,Boots:1} Boots(FY18Q3)
FY18Q1 Footwear Shoes {shoes:2,Sandal:1,Boots:1} Boots(FY18Q3)
FY18Q3 Footwear Boots {shoes:2,Sandal:1,Boots:1} Boots(FY18Q3)
FY18Q1 Clothing Shirt {Shirt:3,Trouser:1} Shirt(FY18Q3)
FY18Q2 Clothing Trouser {Shirt:3,Trouser:1} Shirt(FY18Q3)
FY18Q1 Clothing Shirt {Shirt:3,Trouser:1} Shirt(FY18Q3)
FY18Q3 Clothing Shirt {Shirt:3,Trouser:1} Shirt(FY18Q3)
对lambda函数中的每个组的新值使用命名聚合,使用^{} 和} 中更改} 中聚合,在最后一步中使用^{} :
to_dict
,第二列首先在^{()
,然后在^{相关问题 更多 >
编程相关推荐