16

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
  • 872
  • 1
  • 8
  • 21

1 Answers1

27

Check the docs page

df.dropna(how='all')
Hasnat
  • 531
  • 4
  • 8