我有一个大约20 k行的 Dataframe (dfooc 3)。我想把它分成38个 Dataframe 请注意-我不能使用executemany函数来写这个。
我试着把这个df从python写到我的仓库里。我试着-
import pyodbc
conn = pyodbc.connect('dsn=SNOWFLAKE_ENGINEER_SA;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
import numpy as np
a, b, c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12 = np.array_split(dfooc3, 38)
for index, row in a, b, c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12.iterrows():
cursor.execute("INSERT INTO sf.claim(MemberId,ProgramCode,PolicyNumber,PolicyHolderName,StateCode) values(?, ?, ?, ?, ?, )",row.MemberId,row.ProgramCode,row.PolicyNumber,row.PolicyHolderName,row.StateCode,)
conn.commit()
cursor.close()
Traceback:
line 1, in <cell line: 1>
for index, row in a, b, c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12.iterrows():
ValueError: too many values to unpack (expected 2)
1条答案
按热度按时间gdrx4gfi1#
这不是在多个对象上循环的正确方法,手动为每个 Dataframe 指定一个变量名确实是个坏主意。
请尝试以下操作: