I have a Pandas df I created from reading an email attachment. When inserting into a SQL Server table I see the following error for Parameter 6 which is Call Length column:
Parameter 6 (“”): 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.
Originally Call Length is a timestamp data type, but I’ve converted to a float. In the SQL Server table is shows as a decimal(18,2).
I’ve tried converting like this:
df['Call Length'] = df['Call Length'].dt.total_seconds().astype(float).round(2)
print(df['Call Length'].dtype) #float64
There are no null or empty rows from what I see, there are only about 70 rows.
I’m then just renaming the columns:
df_selected = df_selected.rename(columns={
'From Name': 'FromName',
'From Number': 'FromNumber',
'To Name': 'ToName',
'To Number': 'ToNumber',
'Call Length': 'CallLength',
'Call Start Time': 'CallStartTime',
'Call Direction': 'CallDirection',
})
and then inserting into the table which is where I see the error
insert_nonqueue = f"""
INSERT INTO marketing.Test(FromName, FromNumber, ToName, ToNumber, Result, CallLength,
CallStartTime, CallDirection)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
"""
for index, row in df_selected.iterrows():
cursor.execute(insert_nonqueue, row['FromName'], row['FromNumber'], row['ToName'], row['ToNumber'], row['Result'], row['CallLength'], row['CallStartTime'], row['CallDirection'])
conn.commit()
3