1

I would like to delete every row that contains 0 in order to have cleaner data. However as you can see on the image it shows that 0 is not a null value. Can you guys help me on this? Thank you.

output of my data framework

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
OEA
  • 11
  • 2

3 Answers3

1

As you can read in the pandas doc the method DataFrame.notnull() check if the value are NA, and not for the values equal to zero or in your case a string because you replaced it with 'NA'.

Now to do what you want you can do:

df[(df != 0).all(1)]

As describe in this post

PasNinii
  • 634
  • 8
  • 18
0

Well, when you are trying df.replace(0,'NA') you are subbing in the string value of NA which is not NULL.

You can just use np.nan there like : df.replace(0,np.nan) [with import numpy as np]

Partha Mandal
  • 1,391
  • 8
  • 14
0

By using a replace, you might want to use the following:

df.replace(0, np.nan).dropna()

It basically replaces zeroes by np.nan wich can be eliminated by pandas' .dropna()

Hugolmn
  • 1,530
  • 1
  • 7
  • 20