8

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?

mk2080
  • 692
  • 5
  • 14

1 Answers1

15

Check the docs page

df.dropna(how='all')
Hasnat
  • 401
  • 3
  • 5