Drop rows of tuple containing specific value

Question:

I have a data table with containing tuples of words. I wanted to remove/drop rows that contains the word "tolak" and put it in a new dataset. I wanted to also use the code to later drop the rows that contains no more tuple ("[]"). Here’s what my data looks like:

                  stemming
0  [go, tolak, experience]
1                  [tolak]
2             [nice, look]
3     [love, colour, tabs]

Here’s what I tried so far, but does not make any changes.

df_new = df[df['stemming'] != ('tolak')]
Asked By: Christabel

||

Answers:

You may check with

s = df['stemming'].explode().isin(['tolak'])
df = df.drop(s.index[s])
Answered By: BENY

Just map with a lambda func to test for occurence of word: tolak

df[df['stemming'].map(lambda x: x and 'tolak' in x)]

                  stemming
0  [go, tolak, experience]
1                  [tolak]
Answered By: Shubham Sharma
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.