Home > Net >  How to convert a number into a NaN value in python?
How to convert a number into a NaN value in python?

Time:10-31

I have a negative value that affects my graph. I need to know how to convert for example, -66.23 into a NaN value. Thank you!

CodePudding user response:

Replace a value by another:

>>> df.replace(-66.23, float('NaN'))

CodePudding user response:

To replace all negative values use the pandas built-in Fancy indexing:

df[df < 0] = float('NaN')
  • Related