python 3 中 math.isnan 、numpy.isnan 和 pandas.isnull 之间有什么区别?

los*_*ost 4 numpy python-3.x pandas

NaNDecimal 类型的A会导致:

  1. math.isnan 返回 True
  2. numpy.isnan 抛出 TypeError 异常。
  3. pandas.isnull 返回 False

math.isnan、numpy.isnan 和 pandas.isnull 之间有什么区别?

Chr*_*vos 5

math.isnannumpy.isnan之间的唯一区别是

  • numpy.isnan可以处理列表、数组、元组,
  • math.isnan只能处理单个整数或浮点数。

但是,当您只想检查数字是否为 nan 时,我建议使用math.isnan因为

  • numpy导入时大约需要15MB 内存,而

  • 数学仅占用0.2M 内存

至于pandas.isnull,它不仅对nan返回True ,而且对None python类型也返回True,并且作为numpy,它可以处理每个数字结构。然而,它比numpy还要“重”。