我正在使用看起来像的熊猫数据框:
dealerId | product | bid | supplier | cost
------------------------------------------
dealer1 product1 1.5 supplier1 1.4
dealer1 product1 1.5 supplier2 1.1
dealer1 product2 2.0 supplier3 1.3
dealer1 product2 2.0 supplier4 1.6
dealer2 product2 2.0 supplier4 1.6
dealer2 product2 2.0 supplier4 1.6
dealer2 product2 2.0 supplier4 1.6
dealer3 ... ... ... ...
等等。如何根据经销商ID和产品获得所有可能的独特成本组合?输出的例子
combination = {(1.4,1.3) (1.4,1.6) (1.1,1.3)...}
答案 0 :(得分:1)
你可以尝试
from itertools import combinations
combinations = set(combinations(df['cost'].unique(),2))
如果您正在寻找每个经销商和产品的组合,
df.groupby(['dealerId', 'product']).cost.apply(lambda x: set(combinations(x.unique(), 2)))