由于无效的日期时间格式导致 pyodbc 导入错误 [英] pyodbc import error because of Invalid Datetime format

查看:54
本文介绍了由于无效的日期时间格式导致 pyodbc 导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里查找过,但找不到解决我的问题的方法.我想从 4 个 accces 数据库中获取一个数据框,其中 2 个使用此确切代码,另外 2 个显示此错误:

I´ve already look it up here, but couldn´t find a solution for my problem. I want to get a dataframe from 4 accces databanks and 2 work with this exact code and the other 2 display this error:

DataError: ('22007', '[22007] [Microsoft][ODBC-Treiber für Microsoft Access]Ungültiges Datetime-Format. bei Spaltennummer 11 (dtime) (35) (SQLGetData)')

数据在每个数据库中的格式都相同.请参阅下面的代码:

the Data is in each data bank the same in terms of format. See my code below:

    conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=C:\Users\hoho11.DE\Documents\WLTP_Datenbank\Database_JRC2_SE_UK.accdb;')

conn = pyodbc.connect(conn_str)

cursor = conn.cursor()

for table_info in cursor.tables(tableType='TABLE'):
    print(table_info.table_name)

错误出现在这里:

df_3 = pd.read_sql_query(sql='SELECT * FROM TB_cycles_car', con=conn)
df_3.head()

非常感谢您的支持!!

推荐答案

所以我终于找到了答案.我选择了错误显示列并将其作为字符串导入.我刚刚写道:

So I finally find the answer. I selected the Error showing column and import it as a string. I just wrote:

df = pd.read_sql_query(sql='SELECT ID, ..., Cstr(dtime), dates FROM TB_cycles_car', con=conn)

DataError 不再出现了 :)非常感谢@GordThompson 的帮助!

The DataError didn´t show up anymore :) Thanks a lot @GordThompson for helping!

这篇关于由于无效的日期时间格式导致 pyodbc 导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆