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

Time:01-27

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.

CodePudding user response:

Use:

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

df = df[~mask.all(axis=1)]
  •  Tags:  
  • Related