0

I am working on some problem where i have to take 15th power of numbers, when I do it in python console i get the correct output, however when put these numbers in pandas data frame and then try to take the 15th power, i get a negative number. Example, 1456 ** 15 = 280169351358921184433812095498240410552501272576L, however when similar operation is performed in pandas i get negative values. Is there a limit on the size of number which pandas can hold and how can we change this limit.

Pawan
  • 1,066
  • 1
  • 10
  • 16

3 Answers3

0

If the operations are done in the pydata stack (numpy/pandas), you're limited to fixed precision numbers, up to 64bit.

Arbitrary precision numbers as string, perhaps?

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64
  • using string will not be helpful as other libraries like scikit learn etc. will not work as desired – Pawan Feb 06 '16 at 06:11
0

The pandas dataframe stores its underlying data in a numpy array, so by default on most modern machines it's using 64 bit integers and you're really asking "how do I use arbitrary precision integers with numpy?"

Unfortunately, the answer there is "you don't." If you need arbitrary precision arithmetic along with interesting mathematical operations in python, the choice is SymPy. (as in this stackoverflow answer)

I do not know of any library that wraps SymPy the way pandas wraps numpy.

Community
  • 1
  • 1
Daniel Martin
  • 23,083
  • 6
  • 50
  • 70
0

I was able to overcome by changing the data type from int to float, as doing this gives the answer to 290 ** 15 = 8.629189e+36, which is good enough for my exercise.

Pawan
  • 1,066
  • 1
  • 10
  • 16