What function can be helpful in the following case?

I want to search for some words, for example “center”, in a column with several names (in a column), this I want to show the number of words that match what I was looking for.The names in the column consist of several words “Paris center”

You can use in to check if a word is in a string

>>> 'center' in 'Paris center'

If you want to make sure that you are only getting full words, you can split the text strings on their whitespace like this:

>>> 'center' in 'the center'.split()
>>> 'center' in 'the epicenter'.split()

If you care about punctuation you could try something a bit more complicated using a regex pattern:

>>> 'center' in 'the center.'.split()
>>> import re
>>> 'center' in re.split("[^\w]", "the center.")

Hopefully that gives you somewhere to start :slight_smile:

1 Like