【发布时间】:2020-01-03 18:23:10
【问题描述】:
association_results = filter(lambda rule: len(rule.lhs) == 1, rules)
for rule in sorted(association_results, key=lambda rule: rule.lift):
print(rule)
此代码将在列表中打印所有这样的关联规则(由于安全原因无法显示数据):
{Product 1} -> {Product 2}(conf:0.526,supp:0.001,lift:264.188,conv:2.107)
但是,我需要将这个带有规则的列表导出到 txt 文件,或者最好导出到 Excel。但是当我使用这段代码将它导出到excel时,它给了我一个错误。
[In] : association_results.to_excel('results.xlsx', engine='xlsxwriter')
[Out]: AttributeError: 'filter' object has no attribute 'to_excel
谁能告诉我如何正确地将我的输出导出到 txt 或 Excel 中?
【问题讨论】:
-
你的预期输出是什么
-
@Datanovice 与我的笔记本中显示的输出相同。每行关联规则。
标签: python pandas export market-basket-analysis