Home > Net >  E TypeError: read_sql_query() got an unexpected keyword argument 'dtype'
E TypeError: read_sql_query() got an unexpected keyword argument 'dtype'

Time:12-10

Im using the function read_sql_query, i want to cast types when storing data in dataframe. I tried the rows below, but got this error

E TypeError: read_sql_query() got an unexpected keyword argument 'dtype'

dtypes = {
    'dat1': 'object',
    'dat2': 'object'
}
if function_1 =='f1':
    if (self.table_name == 'table1'):
        df_rows = pd.read_sql_query(sql=sql_query, con=conn, dtype=dtypes)

CodePudding user response:

According to the Documentation at here the dtype is new in version 1.3.0, so I assume, that you have an older version. Try updating it and try again.

Edit: For your requirement with the dates you could use the parse_dates argument. Just give a list of all the columns, that contain dates and Pandas will try to parse them accordingly.

CodePudding user response:

As pointed out you would need to update your pandas module. If this is not an option you can always set the dtypes after you parse the database. See here

Use the "parse_dates" argument for columns that are dates.

  • Related