将 varchar 值“0.0”转换为数据类型 int.DB-Lib 时转换失败

时间:2021-04-23 02:02:02

标签: python pandas database dataframe

我尝试将 python 中的 Pandas 数据帧插入到数据库服务器。

输出的错误说有 varchar 值 '0.0' 不能插入到 Integer db 列中,有没有办法将数据帧中的所有数值都转换为整数?

    {'form_id': dtype('int64'), 'AuthorName': dtype('O'), 'tool_id': dtype('O'), 'Design ID': dtype('O'), 'attribute': dtype('O'), 'gcp_instance': dtype('O'), 'FOAK or SOAK': dtype('O'), 'create_time': dtype('<M8[ns]'), 'QTY': dtype('int32'), 'Probe est. date': dtype('float6
4'), 'EST.Date': dtype('<M8[ns]'), 'MICAP': dtype('int64'), 'CP#': dtype('O'), 'ProjectType': dtype('O'), 'Family_Tech': dtype('O'), 'Area': dtype('O'), 'TemplateName': dtype('O'), 'LID': dtype('O'), 'RISD': dtype('O'), 'Mode': dtype('O'), 'PlannedRFIS': dtype('O'), 'Act
ivity STATUS': dtype('O'), 'WS': dtype('O'), 'TOOL_ID2': dtype('O'), 'iPCRB_Link': dtype('O'), 'Pass': dtype('O'), 'TOOL_ID_join': dtype('O'), 'SPC_M1': dtype('int64'), 'SPC_M2': dtype('int64'), 'SPC_M3': dtype('int64'), 'SPC_M4': dtype('int64'), 'SPCOFF_M1': dtype('int6
4'), 'SPCOFF_M2': dtype('int64'), 'SPCOFF_M3': dtype('int64'), 'SPCOFF_M4': dtype('int64'), 'FDC_M1': dtype('int64'), 'FDC_M2': dtype('int64'), 'FDC_M3': dtype('int64'), 'FDC_M4': dtype('int64'), 'TOOLA_M1': dtype('int64'), 'TOOLA_M2': dtype('int64'), 'TOOLA_M3': dtype('
int64'), 'TOOLA_M4': dtype('int64'), 'RDA_M1': dtype('int64'), 'RDA_M2': dtype('int64'), 'RDA_M3': dtype('int64'), 'RDA_M4': dtype('int64')}
Traceback (most recent call last):
  File "src\pymssql.pyx", line 448, in pymssql.Cursor.execute
  File "src\_mssql.pyx", line 1064, in _mssql.MSSQLConnection.execute_query
  File "src\_mssql.pyx", line 1095, in _mssql.MSSQLConnection.execute_query
  File "src\_mssql.pyx", line 1228, in _mssql.MSSQLConnection.format_and_run_query
  File "src\_mssql.pyx", line 1639, in _mssql.check_cancel_and_raise
  File "src\_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (245, b"Conversion failed when converting the varchar value '0.0' to data type int.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n")

0 个答案:

没有答案