从规则frozensets中提取字符串

问题描述 投票:0回答:1

通过以下声明:

rules = association_rules(frequent_itemsets, metric="lift", min_threshold=1.2) 

我得到了以下格式的规则数据框:

frozenset({'Co_Apples'})

但我需要提取Co_Apples作为字符串。

我怎样才能做到这一点?

python apriori market-basket-analysis frozenset mlxtend
1个回答
1
投票

您可以使用以下代码从freezeset类型列中获取字符串,然后将该字符串转换为unicode。

rules["antecedents"] = rules["antecedents"].apply(lambda x: list(x)[0]).astype("unicode")
rules["consequents"] = rules["consequents"].apply(lambda x: list(x)[0]).astype("unicode")
© www.soinside.com 2019 - 2024. All rights reserved.