JohnDole
JohnDole

Reputation: 565

Delete all rows of a pandas dataframe where certain conditions are met over all columns

My dataframe looks like this:

I want to delete ALL rows (red marked in the picture) where every column has a value like:

"", "nan", "NaT"

I tried several things like dropna, replacing and dropping, but I am can not make it work to delete it.

Upvotes: 0

Views: 316

Answers (1)

jezrael
jezrael

Reputation: 862601

Use:

mask = df.fillna('').isin(["", "nan", "NaT"])

df = df[~mask.all(axis=1)]

Upvotes: 3

Related Questions