View rows of tuple with specific value

Question:

I have rows of data containing tuples of words. I want to see rows that contain a specific word: "accord". Here is an example of my data

id stemming
1 [yes, no, maybe]
2 [accord, yes]
3 [accord]
4 [maybe, do, accord, not]
5 [never, maybe, yes]

Here’s what I expect the new dataframe to look like:

id stemming
2 [accord, yes]
3 [accord]
4 [maybe, do, accord, not]

I tried this code but it says unhashable type: 'Int64Index'

s = data['stemming'].explode().isin(['accord'])
data_new = data.loc(s.index[s])
data_new
Asked By: Christabel

||

Answers:

s = data['stemming'].apply(lambda x: 'accord' in x)
data[s]
Answered By: Panda Kim
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.