0

I have accessed tables stored in Access DB using python, pandas, pyobdc through the pd.read_sql_query command. The table has float values which are used for predictive value calculations and while reading these float values from the table, Python is not reading them exactly as they are but adding a few more digits at the end which results in the wrong predictive values.

For example, value in DB: 0.292244, value retrieved by Python and pandas: 0.29224375

They are giving me incorrect values because they are being used in an exponential function. I have used coerce_float parameter on and off but it doesn't make any changes. Please suggest a way to get it right.

Arcanesaw
  • 29
  • 4
  • Most decimal fractions can't be represented exactly in floating point. – Barmar Dec 10 '21 at 18:15
  • And this is one of them that can't. – Barmar Dec 10 '21 at 18:15
  • If the corresponding column in the Access database is defined as `Numeric(Single)` and the difference between the normalized decimal value (0.292244) and the actual stored decimal value (0.29224398732185364) — which in this case is a difference of 0.000004% — is enough to significantly throw off your calculations then you really should be using a `Numeric(Double)` column to store those values. You will still encounter discrepancies but they will be much, much smaller. – Gord Thompson Dec 11 '21 at 21:21

0 Answers0