I loaded a Pandas DataFrame by reading from a file and doing some pre-processing - that has a few columns of numbers. such as
value
1 13654654328.4567895
2 NULL
3 54643215587.6875455
In order not to lose accuracy I plan to store it as NUMERIC in SQL Server. Since I do not want Pandas to convert my data into float, I load it as string and then use df.to_sql() to insert into SQL.
It worked fine if no NULL exists. However if it contains null, no matter I put "" or np.nan for null, it reported the error as "Error converting data type nvarchar to numeric." Seems that it automatically converts it into empty string which could not be cast into NUMERIC in SQL Server.
Is there any way that I could handle this problem. Hopefully done everything in Python and no further SQL script is needed.
NULLvalues to0instead of""? If not, then I would do that and then you would be able to import them without issue. You could also then update the0values to beNULLNULLwith something that won't appear in the actual data. Perhaps-1would work.