pandas数据框中值的组合

时间:2016-03-27 01:01:59

标签: python python-3.x pandas dataframe

这是我的熊猫数据框:

       Item          Support_Count
0      BREAD              4
1      MILK               4
2      DIAPER             4
3      BEER               3

如何从第1列'项目'生成2和3组项目的所有可能的唯一组合。

示例(2项设置): (面包,牛奶) ,(面包,尿布),(面包,啤酒),(牛奶,尿布)等。

示例(3项集): (面包,牛奶,尿布),(面包,牛奶,啤酒),(牛奶,尿布,啤酒)等。

1 个答案:

答案 0 :(得分:10)

您可以使用// `someImage` is an optional `UIImage` (`UIImage?`), as the initializer is failable let someImage = UIImage(named: "something.png") // `imageWithText` is of type `UIImage` here if let image = someImage { let imageWithText = someImage.withText("Hello World") } // `imageWithText` is of type `UIImage?` here let imageWithText = someImage?.withText("Hello World") 库:

itertools

注意:组合的数量增长非常快,因此生成所有可能的组合可能效率不高。如果您还没有这样做,我建议您查看apriori algorithm实施。

相关问题