Home > OS >  Drop rows of tuple containing specific value
Drop rows of tuple containing specific value

Time:12-10

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')]

CodePudding user response:

You may check with

s = df['stemming'].explode().isin(['tolak'])
df = df.drop(s.index[s])

CodePudding user response:

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]
  • Related