从pandas
0.14(2014年5月发行)开始,支持postgresql。该
sql模块现在用于
sqlalchemy支持不同的数据库风格。您可以为PostgreSQL数据库传递sqlalchemy引擎(请参阅docs)。例如:
from sqlalchemy import create_engineengine = create_engine('postgresql://scott:tiger@localhost:5432/mydatabase')df.to_sql('table_name', engine)
您是正确的,在不支持0.13.1版本的熊猫中,不支持postgresql。如果您需要使用旧版本的熊猫,请使用以下修补版本
pandas.io.sql:https
:
//gist.github.com/jorisvandenbossche/10841234。
我是在前一段时间写的,所以不能完全保证它始终有效,但是基础应该在那里)。如果您将该文件放在工作目录中并导入,那么您应该能够做到(
conPostgreSQL连接在哪里):
import sql # the patched version (file is named sql.py)sql.write_frame(df, 'table_name', con, flavor='postgresql')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)