I want to calculate how many times a list of words appears in a column. Here is my dataframe:
original people resultJohn is a good friend John, Mary 1Mary and Peter are going to marry Peter, Mary 2Bond just met the Bond girl Bond 2Chris is having dinner NaN 0All Marys are here Mary 0I tried to use the code suggested here Check if a column contains words from another column in pandas dataframe:
import pandas as pdimport redf['result'] = [', '.join([p for p in po if re.search(f'\\b{p}\\b', o)) ] for o, po in zip(df.original, df.people.str.split(',\o*')) ]# And after I would try to calculate the number of words in column 'result'but then I receive the following message:
error: bad escape \o at position 1Could anyone make a suggestion?