Reputation: 91
I am working with a panda dataframe that looks like:
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 ... ... ... ...
and so on. How can I get all possible unique combinations of cost based on dealer id and product? example of output
combination = {(1.4,1.3) (1.4,1.6) (1.1,1.3)...}
Upvotes: 1
Views: 51
Reputation: 38415
You can try
from itertools import combinations
combinations = set(combinations(df['cost'].unique(),2))
If you are looking for combinations for each dealer and product,
df.groupby(['dealerId', 'product']).cost.apply(lambda x: set(combinations(x.unique(), 2)))
Upvotes: 1