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

元气小坏坏 提交于 2021-02-08 10:34:22

问题


A NaN of type decimal.Decimal causes:

  1. math.isnan to return True
  2. numpy.isnan to throw a TypeError exception.
  3. pandas.isnull to return False

What is the difference between math.isnan, numpy.isnan and pandas.isnull?


回答1:


The only difference between math.isnan and numpy.isnan is that

  • numpy.isnan can handle lists, arrays, tuples whereas
  • math.isnan can ONLY handle single integers or floats.

However, I suggest using math.isnan when you just want to check if a number is nan because

  • numpy takes approximately 15MB of memory when importing it while

  • math takes only 0,2M of memory

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. However, it is even more "heavy" than numpy.



来源:https://stackoverflow.com/questions/57588107/what-is-the-difference-between-math-isnan-numpy-isnan-and-pandas-isnull-in-pyth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!