使用 Psycopg2 将 Pandas DataFrame 转换为 PostgreSQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33980420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:17:22  来源:igfitidea点击:

Pandas DataFrame to PostgreSQL using Psycopg2

pythonpostgresqlpandaspsycopg2

提问by verkter

Is it possible to write a Pandas dataframe to PostgreSQL database using psycopg2?

是否可以使用 psycopg2 将 Pandas 数据帧写入 PostgreSQL 数据库?

Endgoal is to be able to write a Pandas dataframe to Amazon RDS PostgreSQL instance.

最终目标是能够将 Pandas 数据帧写入 Amazon RDS PostgreSQL 实例。

采纳答案by David Maust

If you use a SQLAlchemy engine around psycopg2, you could probably use df.to_sql. See: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html

如果您在 psycopg2 周围使用 SQLAlchemy 引擎,您可能会使用df.to_sql. 请参阅:http: //pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html