简体   繁体   English

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

[英]What is the difference between math.isnan ,numpy.isnan and pandas.isnull in python 3?

A NaN of type decimal.Decimal causes: NaN类型为decimal.Decimal导致:

  1. math.isnan to return True math.isnan返回True
  2. numpy.isnan to throw a TypeError exception. numpy.isnan引发TypeError异常。
  3. pandas.isnull to return False pandas.isnull返回False

What is the difference between math.isnan, numpy.isnan and pandas.isnull? math.isnan,numpy.isnan和pandas.isnull有什么区别?

The only difference between math.isnan and numpy.isnan is that math.isnannumpy.isnan之间的唯一区别是

  • numpy.isnan can handle lists, arrays, tuples whereas numpy.isnan可以处理列表,数组,元组,
  • math.isnan can ONLY handle single integers or floats. math.isnan 只能处理单个整数或浮点数。

However , I suggest using math.isnan when you just want to check if a number is nan because 但是 ,我建议在只想检查数字是否为nan时使用math.isnan ,因为

  • numpy takes approximately 15MB of memory when importing it while numpy导入时需要大约15MB的内存 ,而

  • math takes only 0,2M of memory 数学仅占用0.2M的内存

As for pandas.isnull it returns True not only for nan but also for None python types and as numpy it can handle every structure of numbers. 至于pandas.isnull,它不仅为nan返回True ,还为None python类型返回True,并且作为numpy它可以处理数字的每种结构。 However, it is even more "heavy" than numpy. 但是,它比numpy更“沉重”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM