1

Ive tried a lot of combination how to remove this empty list from a dataframe, but it didnt work.

index_names = self.df[self.df['stopwords'].len()==0].index
self.df.drop(index_names, inplace=True)

dataframe called df['stopwords'] and it looks like this

dataframe looks like this

goal is to delete the entire row of a dataframe with [] list

4
  • df = df.loc[df['stopwords'].ne([])]? Commented Aug 17, 2021 at 3:40
  • does that equal to drop those empty list? @Ch3steR Commented Aug 17, 2021 at 3:44
  • enter link description here this should find all empty lists and delete them Commented Aug 17, 2021 at 4:19
  • Find and delete all empty lists Commented Aug 17, 2021 at 4:20

2 Answers 2

2

Try astype with bool, since [] will return False

df = df[df['stopwords'].astype(bool)]
Sign up to request clarification or add additional context in comments.

Comments

2

IIUC:

try if they are actual list object:

self.df.loc[~df['stopwords'].map(lambda x:not x)]

else if they are strings then use:

self.df.loc[df['stopwords'].ne('[]')]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.