Let's say we have this df
d = pd.DataFrame({'year': [2010, 2020, 2010], 'colors': ['red', 'white', 'blue'], "shirt" : ["red shirt", "green and red shirt", "yellow shirt"] })
like this:
year colors shirt
0 2010 red red shirt
1 2020 white green and red shirt
2 2010 blue yellow shirt
I want to filter out rows in which the "shirt" column contains the "colors" column also considering the "year" column
desired output:
year colors shirt
0 2010 red red shirt
I tried this d[(d.year == 2010) & (d.shirt.str.contains(d.colors))] but I am getting this error:
'Series' objects are mutable, thus they cannot be hashed
It is a big df that I am working on. How can I solve with some pandas function?
d[(d.year == 2010) & (d.shirt.str.contains('|'.join(d.colors)))]..?