1

While following this answer by @adrtam. I tried to find exact match for line using

A)

print(rules[rules["antecedents"].apply(lambda x: 'line' in x)])

and

B)

print(rules[rules["antecedents"].apply(lambda x: 'line' == x)])

C)

print(rules[rules["antecedents"].apply(lambda x: 'line' == str(x))])

A returns the same result of

print(rules[rules["antecedents"].apply(lambda x: 'line' in str(x))])

B and C returns an empty dataframe. I want to print rows with only exact match (not contains). How do I do this with lambda function?

P.S. Posting as a question because I don't have enough reputation to comment.

raakshasan
  • 55
  • 9
  • 1
    use if condition `print(rules[rules["antecedents"].apply(lambda x: if('line' == x))])` or else use `print(rules[rules["antecedents"] == 'line'])` – Nihal Apr 24 '19 at 07:38
  • Why do you want to 'do this with lambda function'? As answer by @jezrael suggests, why not just use that? – Yash Nag Apr 24 '19 at 07:40
  • Yes that's the easiest way to do it. In retrospect. – raakshasan Apr 24 '19 at 07:43

1 Answers1

3

I believe you need compare by frozenset:

print(rules[rules["antecedents"] == frozenset(['line'])])
raakshasan
  • 55
  • 9
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252