2

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
  • 402
  • 1
  • 5
  • 24

3 Answers3

5
df.dropna(axis = 0, how = 'all')
Sai Sreenivas
  • 1,650
  • 1
  • 6
  • 16
2

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
  • 2,105
  • 1
  • 9
  • 17
-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
  • 3,922
  • 4
  • 16
  • 35