如何将PANDAS DataFrame写入SQL Server表?
我有一个熊猫数据框架,我想将其写入SQL数据库,
dfmodwh
date subkey amount age
09/12 0012 12.8 18
09/13 0009 15.0 20
SQL仓库中有一个现有表,上面有相同的列名称。该表被称为DIM.H2OULTS,
我尝试过
import pyodbc
conn = pyodbc.connect('dsn=azure_warehouse_dev;'
'Trusted_Connection=yes;')
from sqlalchemy import create_engine, MetaData, Table, select
dfmodwh.to_sql(name='dim.h2oresults',con=conn, index=False, if_exists='append')
,但这只是给我执行错误。有没有办法通过pyodbc而不是sqlalchemy写入表,以便如果DFModWH中每天都有新数据,那就不断添加而不是添加写作?
I have a pandas dataframe which i want to write over to sql database
dfmodwh
date subkey amount age
09/12 0012 12.8 18
09/13 0009 15.0 20
there is an existing table in sql warehouse with the same column names. The table is called dim.h2oresults
I tried
import pyodbc
conn = pyodbc.connect('dsn=azure_warehouse_dev;'
'Trusted_Connection=yes;')
from sqlalchemy import create_engine, MetaData, Table, select
dfmodwh.to_sql(name='dim.h2oresults',con=conn, index=False, if_exists='append')
But this just gives me an execution error. Is there a way to write to the table through pyodbc instead of sqlalchemy such that if there is a new data everyday in dfmodwh it just keeps appending and not over writing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您将要使用
to_sql()
I believe you are going to want to use
to_sql()