开始使用免费开始使用

交叉销售产品

这家小型杂货店决定将口香糖与咖啡、麦片或面包进行交叉销售。为判断三者中哪一项效果最好,店主做了一个实验。在一周内,她将口香糖放在收银台旁,并记录所有与咖啡、麦片或面包同时被购买的交易。那天的交易以列表的列表形式提供,变量名为 transactions。每笔交易要么是 ['coffee','gum'],要么是 ['cereal','gum'],要么是 ['bread','gum']

本练习是课程的一部分

Python 中的购物篮分析

查看课程

练习说明

  • 统计包含 coffee 和 gum 的交易数量。
  • 统计包含 cereal 和 gum 的交易数量。
  • 统计包含 bread 和 gum 的交易数量。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Count the number of transactions with coffee and gum
coffee = transactions.count(['____', 'gum'])

# Count the number of transactions with cereal and gum
cereal = transactions.____(['cereal', 'gum'])

# Count the number of transactions with bread and gum
bread = transactions.____(['____', '____'])

# Print the counts for each transaction.
print('coffee:', coffee)
print('cereal:', cereal)
print('bread:', bread)
编辑并运行代码