3 回答
TA贡献1826条经验 获得超6个赞
我刚刚确认以下方法适用于当前版本的pandas、JayDeBeApi和UCanAccess JDBC 驱动程序。有关如何设置 Java/UCanAccess 环境的更多详细信息,请参阅此答案。
import jaydebeapi
import pandas as pd
db_path = "/home/gord/UCanAccessTest.accdb"
ucanaccess_jars = [
"/home/gord/Downloads/JDBC/UCanAccess/ucanaccess-5.0.0.jar",
"/home/gord/Downloads/JDBC/UCanAccess/lib/commons-lang3-3.8.1.jar",
"/home/gord/Downloads/JDBC/UCanAccess/lib/commons-logging-1.2.jar",
"/home/gord/Downloads/JDBC/UCanAccess/lib/hsqldb-2.5.0.jar",
"/home/gord/Downloads/JDBC/UCanAccess/lib/jackcess-3.0.1.jar",
]
classpath = ":".join(ucanaccess_jars)
cnxn = jaydebeapi.connect(
"net.ucanaccess.jdbc.UcanaccessDriver",
f"jdbc:ucanaccess://{db_path}",
["", ""],
classpath,
)
df = pd.read_sql_query("SELECT * FROM Clients", cnxn)
print(df)
"""console output:
ID LastName FirstName DOB
0 1 Thompson Gord 2017-04-01 07:06:27
1 2 Loblaw Bob 1996-09-12 16:03:00
"""
请注意,这适用于从 Access读取到 pandas,但不适用于使用to_sql.
添加回答
举报