Exact same text strings not matching

Viewed 1085

I have two columns in a dataframe title and store containing text strings by which I want to subset the dataframe:

In [84]:
    2631              coffee‑mate sugar free french ...  jet.com
    2633            nestle coffeemate natural bliss ...  jet.com
    2634         coffee‑mate liquid coffee creamer, ...  jet.com
    3085                       coffee‑mate hazelnut ...  jet.com

When I try :

df[(df.title.str.contains('coffee-mate')) & (df.store.str.contains('jet.com'))]

I get:

Out[84]: 
Empty DataFrame
Columns: [title, store]
Index: []

However, when I do this:

df[(df.title.str.contains('coffee')) & (df.store.str.contains('jet.com'))]

I get:

    2631              coffee‑mate sugar free french ...  jet.com
    2633            nestle coffeemate natural bliss ...  jet.com
    2634         coffee‑mate liquid coffee creamer, ...  jet.com
    3085                       coffee‑mate hazelnut ...  jet.com

I don't know what to make of this !

I tried copying the characters 'coffee-mate' to do an equivalency test and got False.

'coffee‑mate' == 'coffee-mate'
Out[92]: False

I have a feeling this is something to do with encoding but don't know how to detect and fix the issue. Can someone help?

1 Answers
Related