Drop rows of tuples containing null value

Question:

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,:]
Asked By: Christabel

||

Answers:

A possible solution:

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

Output:

               stemming
0      [go, experience]
1                [real]
3  [love, colour, tabs]
Answered By: PaulS
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.