This is my pandas dataframe:
Item Support_Count
0 BREAD 4
1 MILK 4
2 DIAPER 4
3 BE
You can use the itertools
library:
import itertools
list(itertools.combinations(df['Item'], 2))
[('BREAD', 'MILK'),
('BREAD', 'DIAPER'),
('BREAD', 'BEER'),
('MILK', 'DIAPER'),
('MILK', 'BEER'),
('DIAPER', 'BEER')]
list(itertools.combinations(df['Item'], 3))
[('BREAD', 'MILK', 'DIAPER'),
('BREAD', 'MILK', 'BEER'),
('BREAD', 'DIAPER', 'BEER'),
('MILK', 'DIAPER', 'BEER')]
Note: The number of combinations grows very quickly so generating all possible combinations may not be efficient. I recommend looking at apriori algorithm implementations if you haven't already done so.