Only remove entirely empty rows in pandas

Viewed 12796

If I have this data frame:

d = {'col1': [1, np.nan, np.nan], 'col2': [1, np.nan, 1]}
df = pd.DataFrame(data=d)

    col1    col2
0   1.0     1.0
1   NaN     NaN
2   NaN     1.0

and want to drop only rows that are empty to produce the following:

d = {'col1': [1, np.nan], 'col2': [1, 1]}
df = pd.DataFrame(data=d)

    col1    col2
0   1.0     1
1   NaN     1

What is the best way to do this?

1 Answers

Check the docs page

df.dropna(how='all')
Related