Home > Blockchain >  Drop rows of tuples containing null value
Drop rows of tuples containing null value

Time:12-11

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,:]

CodePudding user response:

A possible solution:

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

Output:

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