I have a pandas df with a column in which each cell contains a single line of text from Shakespeare plays (100K rows roughly). I need to find exact terms (like 'Rome') while excluding the pattern when it appears inside another word (so not 'Romeo'). I cannot afford to exclude cases like 'Rome.' or 'Rome?'.
I came close with the line below, defining 'Rome' as the variable so I could replace it easily by other terms, but it still doesn't quite work.
df[(df['COL'].str.contains(" " + VAR + " ")) | (df['COL'].str.contains(VAR + ";"))].nunique()