使用 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
Pandas DataFrame to PostgreSQL using Psycopg2
提问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