Background
I am analyzing a Pandas DataFrame that includes the title of different food recipes. My goal is to create categories for the recipe titles based on a keyword in the title.
For instance: 'Spicy Noodle Soup' would be in the Soup category, 'Sour Cream Apple Pie' would be in the Pie category.
I create DataFrames for each of these categories by using the following script
df[df['title'].str.contains('Soup', na=False, case=False)]
df[df['title'].str.contains('Pie', na=False, case=False)]
Problem
I want to exclude specific recipes that have the keyword within the string. The first example that came to mind was excluding 'pancake' from the Cake category. Although many would argue that pancake is a cake, I am not for the purpose of this excercise :) .
A non-optimal solution would be to use ' cake' as the substring, however this would exclude shortcakes, which I would like to include
Question
Is there way to exclude specific substrings when using the str.contains() method? Based on the documentation it doesn't seem like theres a built in way (I could be wrong)