Anggia Bagaskara
Anggia Bagaskara

Reputation: 67

python removing empty list inside a dataframe

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

Upvotes: 1

Views: 290

Answers (2)

BENY
BENY

Reputation: 323226

Try astype with bool, since [] will return False

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

Upvotes: 2

Anurag Dabas
Anurag Dabas

Reputation: 24304

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('[]')]

Upvotes: 2

Related Questions