Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove rows that contains only NaN values in all columns of dataframe? [duplicate]

I have dataframe like below.

Input

df

A     B     C
1     2     1
NaN   4     2
3     NaN   NaN
NaN   NaN   NaN
4     2     NaN
NaN   NaN   NaN

Output

  A     B     C
  1     2     1
  NaN   4     2
  3     NaN   NaN
  4     2     NaN

How can this be done in python

like image 345
pankaj Avatar asked Oct 23 '25 16:10

pankaj


2 Answers

df.dropna(axis = 0, how = 'all')
like image 68
Sai Sreenivas Avatar answered Oct 26 '25 10:10

Sai Sreenivas


you can use:

df.dropna(how='all')

you can look into this thread also: How to drop rows of Pandas DataFrame whose value in a certain column is NaN

like image 45
Tasnuva Avatar answered Oct 26 '25 09:10

Tasnuva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!