My aim is to find City
that matches row from column general_text
, but the match must be exact.
I was trying to use searching IN
but it doesn't give me expected results, so I've tried to use str.contain
but the way I try to do it shows me an error. Any hints on how to do it properly or efficient?
I have tried code based on Filtering out rows that have a string field contained in one of the rows of another column of strings
df['matched'] = df.apply(lambda x: x.City in x.general_text, axis=1)
but it gives me the result below:
data = [['palm springs john smith':'spring'],
['palm springs john smith':'palm springs'],
['palm springs john smith':'smith'],
['hamptons amagansett':'amagansett'],
['hamptons amagansett':'hampton'],
['hamptons amagansett':'gans'],
['edward riverwoods lake':'wood'],
['edward riverwoods lake':'riverwoods']]
df = pd.DataFrame(data, columns = [ 'general_text':'City'])
df['match'] = df.apply(lambda x: x['general_text'].str.contain(
x.['City']), axis = 1)
What I would like to receive by the code above is match only this:
data = [['palm springs john smith':'palm springs'],
['hamptons amagansett':'amagansett'],
['edward riverwoods lake':'riverwoods']]