'Python Pandas read_sql rounds and converts numbers
I'm executing a query on IBM DB2 server with ibm_db_dbi
. Here is my query:
connection = ibm_db_dbi.connect(hostSettings, '', '')
ret = pd.read_sql(query, connection)
It returns DataFrame to me. Everything is fine, but it converts all integers to float. I've another solution for that:
ret['AAA'] = ret['AAA'].astype(int)
But I have a column named as BBB(ret['BBB']
). When I make a query on the database with a client application it returns an integer, which is 343881000298194622
. But pandas returns 3.438810002981946e+24
. I have tried to print reformatted value like that:
print(["{0:0.2f}".format(i) for i in ret['BBB']])
It prints the value as 343881000298194624.00
, not 343881000298194622.00
(The 2 at the end of the number).
What's wrong here? Why can't I print this value as database query?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|