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
CodePudding user response:
s = data['stemming'].apply(lambda x: 'accord' in x)
data[s]
