将数据从pandas数据帧传输到IBM DB2表时出错

问题描述 投票:0回答:1

我能够在IBM Cloud上建立与db2的连接,但无法将大小为40000 * 150的df复制到表中。这是代码:

data = pd.read_excel("C:\Users\PranshuSahijwani\Desktop\kp\data@0409\Pharma_Automated_Snow.xlsx")
data.fillna("Others")

tuple_of_tuples = tuple([tuple(x) for x in data.values])
#values = ",".join([tuple(x) for x in subset])

cnn = ibm_db.connect("DATABASE=BLUDB;HOSTNAME=dashdb-txn-sbox-yp-lon02- 
01.services.eu-gb.bluemix.net;\
PORT=50000;PROTOCOL=TCPIP;UID=uid;PWD=pwd;", "", "")


start = time.time()
placeholders = ', '.join(['?'] * len(data.columns))  
insert_sql = "INSERT INTO zkb70555.regionsAndServers VALUES ( " + placeholders + ")"
stmt_insert = ibm_db.prepare(cnn, insert_sql)
ibm_db.execute_many(stmt_insert, tuple_of_tuples)

end = time.time()
print end-start

我收到的错误如下所示:enter image description here

需要改变什么?

pandas db2 ibm-cloud
1个回答
0
投票

专门传递给execute_many的数组必须具有相同的类型。上述错误表示插入的数据可能不是这种情况。驱动程序在将请求发送到数据库服务器之前检查数据,并且客户端返回此错误。

© www.soinside.com 2019 - 2024. All rights reserved.