I'm trying to use read_sql_query()
to read a query from MySQL database, one of the field in the database, its type is double(24, 8)
, I want to use dtype=
parameter to have full control of the datatypes and read it to decimal
, but seems like pandas can't recognize decimal
type so I had to read it to Float64
In the database, the values for this field look like this:
Value
100.96000000
77.17000000
1.00000000
0.12340000
Then I'm trying to read it from Python code:
from decimal import *
dtypes = {
'id': 'Int64',
'date': 'datetime64',
'value': 'Float64'
}
df = pd.read_sql_query(sql_query, mysql_engine, dtype=dtypes)
but after reading the data from the code above, it looks like this:
Value
100.96
77.17
1.0
0.1234
How can I read this column to decimal
and keep all the digits? Thanks.