我正在尝试使用以下代码将多行从数据帧插入到 SQL Server。但我收到错误消息:
[ODBC SQL Server 驱动程序][SQL Server]无效的列名“投资”。")
SQL 表有三列 - Investment、variable、value1。
df = pd.read_excel(path, sheet_name='final')
print ("Column headings:")
df = df.melt(id_vars = 'Investment')
print(df)
for r in df.columns.values:
df[r] = df[r].map (str)
df[r] = df[r].map (str.strip)
tuples = [tuple (x) for x in df.values]
new_list = chunks(tuples, 1000)
query = """insert into Equity_Indicators(Investment, variable, value1) values (?, ?, ?)"""
cursor.executemany (query, new_list[0])
new_list 中的值:
[('2000-01-31 00:00:00', 'VTL US Equity', '4.2572'), ('2000-02-29 00:00:00', 'VTL US Equity', '4.2572') , ('2000-03-31 00:00:00', 'VTL US Equity', '4.4384'), ('2000-04-30 00:00:00', 'VTL US Equity', '4.937') , ('2000-05-31 00:00:00', 'VTL US Equity', '4.6218')]
Qyouu
杨魅力
相关分类