Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract string from rules frozensets

With the following statement:

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

I get a data frame of rules in the format:

frozenset({'Co_Apples'})

But I need to extract a Co_Apples as a string.

How can I do that?

like image 328
Erez Ben-Moshe Avatar asked Dec 17 '22 21:12

Erez Ben-Moshe


1 Answers

rules["antecedents"] = rules["antecedents"].apply(lambda x: ', '.join(list(x))).astype("unicode")

It is work for me. Thanks Frank Herfert save my day!

like image 124
Johnny Hsiao Avatar answered Jan 02 '23 10:01

Johnny Hsiao