I have the problem with pandas method: read_sql I select four columns from database and about 100 rows.
import pymysql
sql = "SELECT `opens`,`high`,`low`,`close` FROM `dbname`"
result = ""
try:
with c as cursor:
cursor.execute(sql)
result = cursor.fetchall()
conn.commit()
finally:
conn.close()
print(result)
Result of this above example returns values in proper format, whit good precision for double and data stored in a database.
opens high low close
0.00016445 0.00016445 0.00016445 0.00016445
But with:
import pandas as pd
df = pd.read_sql(sql,conn,coerce_float=False)
print(df)
The result is:
opens high low close
0.000164 0.000164 0.000164 0.000164
I need to use data like are in a database and that cause a lot of issues during resampling data. Can anyone help me with that?
I was trying to change casting, and added that options 'coerce_float=False' but that seems to be worthless
EDIT 9.07.2018 - 1:
SQL TABLE SHAME:
CREATE TABLE `dbname` (
`ids` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` int(10) unsigned NOT NULL,
`high` double NOT NULL,
`low` double NOT NULL,
`opens` double NOT NULL,
`close` double NOT NULL,
`volume` double NOT NULL,
`weightedAverage` double NOT NULL,
PRIMARY KEY (`ids`)
) ENGINE=InnoDB AUTO_INCREMENT=16113 DEFAULT CHARSET=latin1
EDIT 10.07.2018 - 2: Resampling example:
df.set_index('timestamp', inplace=True)
#converting timestamp to DatatimeIndex
df.index = pd.to_datetime(df.index, unit='s')
conversion = {'opens': 'first', 'high': 'max', 'low': 'min', 'close': 'last'}
#df = df.resample('15Min', how = conversion, base=0)
df = df.resample(self.period, closed='right').agg(conversion)
print(df)
EDIT 11.07.2018 - EDIT 1 I have partially solution for that problem: I added before any action:
pd.set_option('display.float_format', lambda x: ('%.8f' % x).rstrip('.0'))
Alright, everything works fine with that settings. I solved that problem. Maybe someone will have the same problem and quick find my solution.