Home > Software engineering >  Remove row if the one column list is empty
Remove row if the one column list is empty

Time:03-17

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

CodePudding user response:

If there are empty lists casting them to boolean, so get Trues for not empty values and filter in boolean indexing:

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

But if empty strings () compare for not equal:

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

CodePudding user response:

Use:

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

CodePudding user response:

You can use list comprehension:

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