将数据从熊猫数据框传输到IBM DB2表时出错

时间:2018-10-05 10:15:17

标签: pandas db2 ibm-cloud

我能够建立到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

需要更改什么?

1 个答案:

答案 0 :(得分:0)

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