python - 将熊猫数据框加载到 SQL Server 2012
问题描述
我尝试将熊猫数据框加载到 SQL Server。数据框具有以下列:
- 用户 ID - 整数
- saleId - 整数
- regTime - 整数
- countryId - 整数
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
for index, row in users.iterrows():
cursor.execute('INSERT INTO [dbo].[users]([userId],[saleId],[regTime],[countryId]) values (?,?,?,?)',
row['userId'],
row['saleId'],
row['regTime'],
row['countryId'])
cnxn.commit()
cursor.close()
cnxn.close()
但我有以下错误:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
<ipython-input-103-383c1873cad8> in <module>
4 row['saleId'],
5 row['regTime'],
----> 6 row['countryId'])
7 cnxn.commit()
8 cursor.close()
ProgrammingError: ('Invalid parameter type. param-index=0 param-type=numpy.int64', 'HY105')
countryId 列的值从 0 到 9(代码)
我该如何纠正?
解决方案
推荐阅读
- javascript - Express node.js api app.post 确实适用于 / 但不适用于 /path
- javascript - 在多个参数之间导航 - React js
- java - Java loop , print out odd numbers
- python - "Visualizing [and Understanding] Recurrent Networks" using LSTM's cell state at each timestep
- c# - Getting original IP Address when user is connected to VPN C#
- operating-system - 哪些微控制器不需要 USB 到 UART 驱动程序来与计算机连接?
- python-3.x - How to fetch entire row data based on index and convert to YAML
- css - SASS: Is there a way to cusomize the sass syntax?
- python - AttributeError: 'NoneType' object has no attribute 'text' -
- java - Adding snapshotlisteners to multiple documents id at the same time in firebase