I'm trying to get the count of the contents of one column in a second column in pandas. I would like to put the frequency counts in a new column called frequency.
I would like to find the number of times the string in my [Keyword] column is found in the [Description] column in a new column called [Frequency].
Desired output
[keyword] [Description] [Frequency]
car car dog car car 3
car car dog dog dog 1
new car old car car dog 0
Code I've tried
I tried the following code, but had two problems. (The frequency count wasn't accurate and formatting was completely wrong).
s = df['Keyword']
pat = r'\b{}\b'.format('|'.join(s))
from sklearn.preprocessing import MultiLabelBinarizer
mlb = MultiLabelBinarizer()
df_new = pd.DataFrame(mlb.fit_transform(df['Description'].str.findall(pat)),
columns=mlb.classes_,
index=df.index).reindex(columns=s, fill_value=0)