2

So I have this long number (i.e: 1081546747036327937), and when I cleaned up my data in pandas dataframe, I didn't realize Python converted it to complex number (i.e: 1.081546747036328e+18).

I saved this one as csv. The problem is, I accidentally deleted the original file, tried to recover it but no success this far, so... is there a way to convert this complex number back to their original number?

I tried to convert it to str using str(data) but it stays the same (i.e: 1.081546747036328e+18).

Sae
  • 79
  • 7

2 Answers2

3

As you were said in comment, this is not a complex number, but a floating point number. You can certainly convert it to a (long) integer, but you cannot be sure to get back the initial number.

In your example:

i = 1081546747036327937
f = float(i)
j = int(f)
print(i, f, j, j-i)

will display:

1081546747036327937 1.081546747036328e+18 1081546747036327936 -1

This is because floating points only have a limited accuracy and rounding errors are to be expected with large integers when the binary representation requires more than 53 bits.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
2

As can be read here, complex numbers are a sum of a real part and an imaginary part.

3+1j is a complex number with the real value 3 and a complex value 1

You have a scientific notation (type is float), which is just an ordinary float multiplied by the specified power of 10.

1e10 equals to 1 times ten to the power of ten

To convert this to int, you can just convert with int(number). For more information about python data types, you can take a look here

Stephan T.
  • 5,843
  • 3
  • 20
  • 42