0

I have a Pandas dataframe with columns of type float64

I try to compute apply sum function on some columns by numpy.sum

When I active the function np.sum(x[col_name]) I receiving the result of 'inf'

But when I check where is the 'inf' value by np.where(np.isinf(x[col_name])) I received empty results.

So, What I do wrong...

Thanks.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
MAK
  • 605
  • 9
  • 19

1 Answers1

2

The problem appears to be that one of the numbers in your data, is bigger than the max np.float64 accepts. If you run, np.finfo(np.float64), you'll see the biggest number this dtype accepts:

Machine parameters for float64
---------------------------------------------------------------
precision =  15   resolution = 1.0000000000000001e-15
machep =    -52   eps =        2.2204460492503131e-16
negep =     -53   epsneg =     1.1102230246251565e-16
minexp =  -1022   tiny =       2.2250738585072014e-308
maxexp =   1024   max =        1.7976931348623157e+308
nexp =       11   min =        -max
--------------------------------------------------------------

According to this answer: https://stackoverflow.com/a/37272717/4014051 python objects use an arbitrary length implementation, therefore the solution would be to make the dtype of your array object. This means that your code will be slower overall, as your data are not numpy objects, but presumably it will output the correct sum.

Ralvi Isufaj
  • 442
  • 2
  • 9