I have a need to convert an 18 digit float64 pandas column to an integer or string to be readable avoiding the exponential notation. But I am not successful so far.
df=pd.DataFrame(data={'col1':[915235514180670190,915235514180670208]},dtype='float64')
print(df)
col1
0 9.152355e+17
1 9.152355e+17
Then I tried converting it to int64. But last 3 digits going wrong.
df.col1.astype('int64')
0 915235514180670208
1 915235514180670208
Name: col1, dtype: int64
But you see .. the value is goin wrong. Not sure why. I read from documentation as int64 should be able to hold an 18 digit number.
int64 Integer (-9223372036854775808 to 9223372036854775807)
Any idea what I am doing wrong ? How can I achieve my requirement ?
Giving further info based on Eric Postpischil comment. If float64 can't hold 18 digits, I might be in trouble. Thing is that I get this data through a pandas read_sql function call from DB. And it automatically type casted to float64. I don't see an option to mention datatype in pandas read_sql()
Any thoughts from any one on what I can do to overcome this problem ?
Float64cannot represent 915235514180670190. When that decimal numeral is converted toFloat64, the result is the nearest representable value, 915235514180670208. Converting theFloat64to decimal cannot reproduce the original value because it is gone.