Dewani
Dewani

Reputation: 137

Drop rows of tuples containing null value

I have a data table with containing tuples of words. I want to drop the rows (pf tuple) that contains no words ("[]"). Here's what my data looks like, in which I expect 3rd row to be removed in the new dataset.

                  stemming
0         [go, experience]
1                   [real]
2                       []
3     [love, colour, tabs]

Here's what I tried so far:

df_new['stemming']=df['stemming].apply(lambda x : [t for t in x if t != ()])
df_new.loc[df_new['stemming'].apply(len)>0,:]

Upvotes: 1

Views: 96

Answers (1)

PaulS
PaulS

Reputation: 25393

A possible solution:

df.loc[df.stemming.map(len).ne(0)]

Output:

               stemming
0      [go, experience]
1                [real]
3  [love, colour, tabs]

Upvotes: 1

Related Questions