0

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
  • 19,076
  • 4
  • 25
  • 52
OEA
  • 1

3 Answers3

0

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

Ninii
  • 433
  • 5
  • 11
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,311
  • 6
  • 13
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,430
  • 1
  • 5
  • 19