Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only remove entirely empty rows in pandas

Tags:

python

pandas

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?

like image 704
mk2080 Avatar asked Dec 12 '25 11:12

mk2080


1 Answers

Check the docs page

df.dropna(how='all')
like image 136
Hasnat Avatar answered Dec 16 '25 10:12

Hasnat