I know it's quite straightforward to use df.str.contains()
to check if the column contains a certain substring.
What if I want to do the other way around: check if the column's value is contained by a longer string? I did a search but couldn't find an answer. I thought this should be easy, like in pure python we could simply 'a' in 'abc'
I tried to use df.isin
but seems it's not designed for this purpose.
Say I have a df looks like this:
col1 col2
0 'apple' 'one'
1 'orange' 'two'
2 'banana' 'three'
I want to query this df on col1
if is contained by a string appleorangefruits
, it should return me the first two rows.