Python 使用sqlalchemy和psycogp2将数据帧推送到postgres
我正在尝试将数据帧写入postgres。因为DBAPI使用的是psycogp2Python 使用sqlalchemy和psycogp2将数据帧推送到postgres,python,python-2.7,postgresql,Python,Python 2.7,Postgresql,我正在尝试将数据帧写入postgres。因为DBAPI使用的是psycogp2 localconn='postgresql+psycopg2://postgres/PSWD@localhost:5432/localPG' localEng=engine.create_engine(localconn) df.to_sql("DUMMY", localEng) 但是它的抛出错误(psycopg2.OperationalError)无法将主机名postgres转换为地址:名称或服务未知 local
localconn='postgresql+psycopg2://postgres/PSWD@localhost:5432/localPG'
localEng=engine.create_engine(localconn)
df.to_sql("DUMMY", localEng)
但是它的抛出错误(psycopg2.OperationalError)无法将主机名postgres转换为地址:名称或服务未知
localPG是数据库名称
我哪里做错了?您编写的格式错误,请使用以下格式:
localEng = create_engine('postgresql+psycopg2://[user]:[pass]@[host]:[port]/[schema]', echo=False)
当然,您应该用等效的数据库凭据替换括号中的每个参数。非常感谢@rachid。我找了很多。。到处都是我使用的格式。不管怎么说,这真的很有帮助。