Search code examples
pythonnumbersgoogle-colaboratorynan

How to convert a number into a NaN value in python?


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!


Solution

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

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