Export from pandas to MS SQL using to_sql and sqlalchemy

Asked

Viewed 191 times

0

My problem is with Float values

example:

df = pd.DataFrame([1.45])

conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params)
engine = create_engine(conn_str)

df.to_sql(name='teste',con=engine, if_exists='replace',index=False)

table is generated in my SQL successfully, the problem is the shape of the float that comes with comma instead of dot (1.45) how do I export with point separator(1.45)

Obs: in other tables of my bank are with separator by point

Thank you.

1 answer

0

Use locale:

import locale
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
  • Hi Marcelo, sorry for the ignorance, but I didn’t understand which part I use this code.

  • In the entry point of your program. At the beginning of it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.