Insert into DB2 table from a python dataframe(从 python 数据框插入 DB2 表)
问题描述
我正在使用 python 库 IBM_DB,我可以通过它建立连接并将表读入数据帧.从 python 中的数据帧源写入 DB2 表(INSERT 查询)时会出现问题.
I am using python library IBM_DB with which I am able to establish connection and read tables into dataframes. The problem comes when writing into a DB2 table (INSERT query) from a dataframe source in python.
以下是连接示例代码,但有人可以帮我如何将数据帧中的所有记录插入到 DB2 中的目标表中吗?
Below is sample code for connection but can someone help me how to insert all records from a dataframe into the target table in DB2 ?
如果给定带有硬编码值的 SQL 语法,我也可以手动插入记录:
I am also able to insert a record manually if given SQL syntax with hard coded values :
我无法实现的是从数据框插入并将其附加到表中.我也尝试过 DATAFRAME.to_SQL() ,但出现以下错误:
What I am unable to achieve is to insert from a dataframe and append it to the table. I've tried DATAFRAME.to_SQL() as well but it errors out with the following :
这个错误说:
推荐答案
您可以使用 ibm_db.execute_many()
将 pandas 数据帧写入 ibm db2.
You can write a pandas data frame into ibm db2 using ibm_db.execute_many()
.
这篇关于从 python 数据框插入 DB2 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!