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
e.g.
>>> 'center' in 'Paris center'
True
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()
True
>>> 'center' in 'the epicenter'.split()
False
If you care about punctuation you could try something a bit more complicated using a regex pattern:
>>> 'center' in 'the center.'.split()
False
>>> import re
>>> 'center' in re.split("[^\w]", "the center.")
True
Hopefully that gives you somewhere to start
1 Like