Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A possible solution:

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

Output:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading