4

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

pankaj
  • 420
  • 1
  • 8
  • 26

3 Answers3

5
df.dropna(axis = 0, how = 'all')
Sai Sreenivas
  • 1,690
  • 1
  • 7
  • 16
3

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

Tasnuva Leeya
  • 2,515
  • 1
  • 13
  • 21
-1

You can select the df which is not NaN rather than dropping it:

df = df[~((df['A'].isna()) & (df['B'].isna()) & (df['C'].isna()))]

This gives a bit more capability if you want to filter your df by certain values of each column.

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

You can use df.dropna?? to get the information about the dropna functionality.

Jonas Palačionis
  • 4,591
  • 4
  • 22
  • 55