pythonexasolutionexasol

How to specify data type in PyExasol export_to_pandas


How can I pass datatype parameters in export_to_pandas API. and can I change column names to lower cases ?

from pyexasol import ExaConnection con = ExaConnection(dsn=dns, user=user, password=password) con.execute('OPEN SCHEMA SCHEMATEST1')

data = con.export_to_pandas('select * from TABLETEST1')


Solution

  • You may specify any parameters used for pandas.read_csv and pass it using callback_params argument.

    For example:

    callback_params = {
        'names': ['A', 'B', 'C'],
        'header': 0,
        'dtype': {'A': numpy.float64, 'B': numpy.int32, 'C': 'Int64'}
    }
    
    
    data = con.export_to_pandas('select * from TABLETEST1', callback_params=callback_params)
    

    Please note that names of columns are actually stored uppercased in Exasol. You may use connection option lower_ident=True to lower case for normal .execute(), but it is not going to work with .export_to_pandas. The only way is to specify column names manually or to modify each name later.