python - 带有 if_exists="append" 的 df.to_sql 失败并出现 TypeError: Invalid Argument sent to create_engine
问题描述
我目前正在使用 0.24.2 的 Pandas、11.2 的 Postgresql 和 1.3.2 的 sqlalchemy 尝试使用if_exists="append"
. 代码运行时返回以下错误:
TypeError: Invalid argument(s) 'if_exists' sent to create_engine(), using
configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the
keyword arguments are appropriate for this combination of components.
代码很简单,看起来与文档中的示例完全相同:
def write_to_db(df):
engine = create_engine(
"postgresql://esammons@localhost:5432/testdb", if_exists='append'
)
df.to_sql("ctcl", engine)
该代码在没有该if_exists
选项的情况下执行。
解决方案
尝试:
def write_to_db(df):
engine = create_engine(
"postgresql://esammons@localhost:5432/testdb"
)
df.to_sql("ctcl", engine, if_exists='append')
推荐阅读
- python - 如何用 Python 处理类似的符号?
- sql - 使用子查询和 JOIN 对 COUNT 应用 MAX | SQL 甲骨文
- java - 子类的抽象类的线程调用?
- forms - 从 PHP 表单提交数据时,MYSQL 数据库显示空白条目?
- python - Python 最佳实践:最好使用嵌套函数或私有函数语法?
- javascript - 循环json数据并显示在模态表中
- python - 即使我已经按下它,我的键也不起作用 Python Pygame
- r - ggplot核密度图线重叠不正确
- firebase-realtime-database - 如何从 Firebase 数据库密钥中检索/解码时间戳?
- azure-devops - Azure Devops 中的秘密管道参数