NSD
NSD

Reputation: 13

Remove row if the one column list is empty

How can I remove all the rows if the value of one column list is empty?

enter image description here

so the end result looks like this:

enter image description here

Upvotes: 0

Views: 57

Answers (3)

jezrael
jezrael

Reputation: 862396

If there are empty lists, cast them to boolean, we will get Trues for non-empty values and filter them using boolean indexing:

df = df[df['ids'].astype(bool)]

But if empty strings () compare for not equal:

df = df[df['ids'].ne('()')]

Upvotes: 1

TheFaultInOurStars
TheFaultInOurStars

Reputation: 3608

You can use list comprehension:

df["id"] = [x for x in df["id"] if len(x) >= 1]

Upvotes: 0

Muhammad Hassan
Muhammad Hassan

Reputation: 4229

Use:

df = df[df['ids'].map(len)>1]

Upvotes: 0

Related Questions