0

The values in the mysql table contain 17 decimal places (double). e.g., 0.12345678901234567 or 0.00987654321098765.

When I try to import data from mysql by python pandas, the dataframe change my data from double to float. the value in df becomes 0.123457 or 0.00987654 (you can observe that the value in df is 6 sig. fig.) It creates the problem that I need the complete value of a data up to 17 decimal places.

The code I ran:

db_conn_str = 'mysql+pymysql://username:password@some_site/some_database'
db_conn = create_engine(db_conn_str)
df = pd.read_sql('SELECT * FROM some_table', con=db_conn)

How can I modify the pd.read_sql so I could get all decimal places of my data values? Thanks.

  • Convert numeric data to its string representation - it won't be rounded/truncated. – Akina Oct 23 '20 at 11:33
  • this is impossible because i need to do calculation in dataframe. – user5151477 Oct 23 '20 at 11:35
  • Convert back after receiving before calculations. – Akina Oct 23 '20 at 11:47
  • Could it be a display problem as [this post](https://stackoverflow.com/a/36909497/3218693) suggested? – Bill Huang Oct 23 '20 at 11:49
  • @Akina I dont think it is possible because I have just checked the dtype of df. It shows float64. So, it is weird to get this result during import. Or you can show me the code, how can I read the sql as string in pandas? df column is in this arrangement: datetime, columnA, columnB, columnC, so it is very simple df. Thanks. – user5151477 Oct 23 '20 at 12:07

0 Answers0