Python Dataframe To Sql Numbers Are Getting Rounded
I have a dataframe like this: ID Value Value2 1079712667 169945540 18.103862 1079712668 NA 100.509234 1079712669 260
Solution 1:
The issue was raised two years ago : here.
After that a new feature was introduced to allow you to override the default chosen type using the dtype
kwarg in to_sql
.
dtype
can be set to any of the known SQL data types.
Here is the link to all these types.
dtype
must be a dictionary with column names as keys and SQL data type as values :
dtype={'Value1': DOUBLE, 'Value2: DOUBLE}
Warning: If you look at jorisvandenbossche answer in the git issue thread (here), there might be some approximation issues.
@Nickil Maveli : I like your trick. Using str
while writing to the SQL database might be the best solution though to avoid any problems.
Post a Comment for "Python Dataframe To Sql Numbers Are Getting Rounded"