使用SQLalchemy在Python中写入PostgreSQL数据库

使用SQLalchemy在Python中写入PostgreSQL数据库,python,pandas,postgresql,sqlalchemy,google-colaboratory,Python,Pandas,Postgresql,Sqlalchemy,Google Colaboratory,我试图在我的google Colab笔记本中使用Python写入我的postgres数据库,但在尝试pandas“to_sql”函数时出现了这个错误 代码如下:(此部分不产生错误) 尝试运行to.sql(下面的函数)时引发错误: 我能够成功连接到postgres实例,并且在创建“engine”变量后没有收到任何错误 我尝试上载的pandas数据帧中的数据类型为: timestamp object open float64 high float64 low

我试图在我的google Colab笔记本中使用Python写入我的postgres数据库,但在尝试pandas“to_sql”函数时出现了这个错误

代码如下:(此部分不产生错误)

尝试运行to.sql(下面的函数)时引发错误:

我能够成功连接到postgres实例,并且在创建“engine”变量后没有收到任何错误

我尝试上载的pandas数据帧中的数据类型为:

timestamp     object
open         float64
high         float64
low          float64
close        float64
volume       float64
dtype: object
我认为这可能是时间戳列数据类型的问题,但我不确定Postgres中的等效值应该设置为什么。

如果您从pandas df.to_sql获得“意外argument Fetch”

add方法='multi'


df.to_sql('dbname',con=engine,if_exists='append',index=False,method='multi'

您是如何为这个环境安装软件包的?看起来您的
psycopg2
pandas
版本不兼容,请尝试卸载,使用Condagogle Colab重新安装会处理版本控制,所以我没有安装任何东西,我只是使用了导入命令。啊,好的。在这种情况下,我不确定。为了更好地解决您的问题,您能分享您的代码和完整的日志错误吗?用完整的代码更新
df.to_sql('dbname', con=engine, if_exists='append', index = False)

TypeError
/usr/local/lib/python3.7/dist-packages/sqlalchemy/dialects/postgresql/psycopg2.py in do_executemany(self, cursor, statement, parameters, context)
    907                 template=executemany_values,
    908                 fetch=bool(context.compiled.returning),
--> 909                 **kwargs
    910             )
    911 

TypeError: execute_values() got an unexpected keyword argument 'fetch'
timestamp     object
open         float64
high         float64
low          float64
close        float64
volume       float64
dtype: object