Home > Software design >  Removing numbers from dataframe that lie within range
Removing numbers from dataframe that lie within range

Time:12-28

I have a pandas dataframe that contains values between -1000 to 1000. I want to eliminate all the numbers between the range of -0.00001 to 0.00001 i.e replace them with NaN. It is worth mentioning that my df contains numerous instances of very small positive and negative numbers that I want to include within this range as well e.g. 6.26478E-52.

How do I go about doing this?

P.S. I am attaching an image of the first few rows of my df for reference.

enter image description here

CodePudding user response:

IIUC use if need less like -0.00001 and 0.00001:

df = df.mask(df.lt(-0.00001) | df.lt(0.00001))

is same like below 0.00001:

df = df.mask(df.lt(0.00001))

Or if need values between:

df = df.mask(df.gt(-0.00001) & df.lt(0.00001))
  • Related