问题
A NaN
of type decimal.Decimal causes:
- math.isnan to return True
- numpy.isnan to throw a TypeError exception.
- 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