Specifying dtypes for read_sql in pandas Specifying dtypes for read_sql in pandas pandas pandas

Specifying dtypes for read_sql in pandas


What about cast() and convert()?

'SELECT cast(ARP as float32()), cast (ACP as float32()) from train where seq < 5'

or something similar.

http://www.smallsql.de/doc/sql-functions/system/convert.html


Take a look in this github issue, looks like they are inclined to add the option.


You can use pandas read_sql_query which allows you to specify the returned dtypes (supported only since pandas 1.3).

pd.read_sql_query('select ARP, ACP from train where seq < 5', connection,                  dtype={'ARP': np.float32, 'ACP': np.float32})