如何将python中的数字转换为NaN值?

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

我有一个负值影响了我的图表。我需要知道如何将 -66.23 转换为 NaN 值。谢谢!

用另一个值替换一个值:

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

要替换所有负值,请使用 pandas 内置 Fancy indexing:

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