Issue
I have a pandas dataframe that I'm writing to a table in SQL Server. The data frame contains the following dtypes:
Contact_ID object
Skill_No float64
Skill_Name object
Campaign_No float64
Campaign_Name object
Agent_No float64
Agent_Name object
Team_No float64
Team_Name object
Start_Date object
Disp_Code float64
Disp_Name object
Disp_Comments object
When I try to write to SQL Server I get the following error:
ProgrammingError: ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 16 (""): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision. (8023) (SQLExecDirectW)')
I have tried converting the data types in my sql table to decimal, float, and back again but nothing seems to work. How can I solve this?
Solution
I encountered this same error message, which in my case was being caused by some float('inf') and float('-inf') values in some columns of my pandas.DataFrame. I resolved this by changing my infinity values to 1 or -1, which made sense in the context of my project. Alternatively, you could remove those rows.
df.loc[df[col_name] == float('-inf'), col_name] = -1
df.loc[df[col_name] == float('inf'), col_name] = 1
Answered By - noobnoob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.