I have a dataFrame like this:
df = pd.DataFrame({'products' : ['a,b,c', 'a,c', 'b,d','a,b,c']})
products
0 a,b,c
1 a,c
2 b,d
3 a,b,c
And I have created a dictionary that maps specific products to a certain category:
mydict = {'good':['a'],'bad':['d'],'neutral':['b','c','a']}
I'm trying to create a new column, let's say df['quality'] that adds the dictionary key (product category), if any of the products in df['products'] are included in the values for that particular key.
Namely, the final output should look like so:
products quality
0 a,b,c good, neutral
1 a,c good, neutral
2 b,d neutral, bad
3 a,b,c good, neutral
Any idea? Am I overcomplicating the problem?