delete initial rows which have nan values in all columns in a dataframe

46 Views Asked by At

enter image description hereI have a pandas dataframe with nan values.I want to delete initial rows with all nan values but do not want to delete all rows afterthat thoough they may have nan values in entire row.

i use dropna(how="all") but it will delete all rows which have nan values in entire rows. But I want to delete only initial rows with all nan values

1

There are 1 best solutions below

0
On

You can craft a boolean mask with notna, any, and cummax for boolean indexing:

m = df.drop(columns='Date').notna().any(axis=1).cummax()
out = df[m]