Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 484
lostlostlostlostlost Avatar asked Oct 27 '25 04:10

lostlostlostlostlost


1 Answers

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.

like image 122
Christos Palyvos Avatar answered Oct 30 '25 01:10

Christos Palyvos