Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17041

Inserting pandas dataframe with float values into Oracle

$
0
0

I can insert normal values like integer, string into Oracle from pandas data frame but when I try float type values , sqlalchemy gives below errors

sqlalchemy.exc.ArgumentError: Oracle FLOAT types use 'binary precision', which does not convert cleanly from decimal 'precision'.  Please specify this type with a separate Oracle variant, such as Float(precision=53).with_variant(oracle.FLOAT(binary_precision=176), 'oracle'), so that the Oracle specific 'binary_precision' may be specified accurately.

here is the complete source code

import pandas as pdimport osimport sqlalchemy as safrom sqlalchemy import textfrom sqlalchemy.dialects import oracleoracle_db = sa.create_engine('oracle://username:password@instance/?service_name=MBCDFE')conn = oracle_db.connect()df = pd.DataFrame({    #"column1": [1, 1, 1], #- inserting into DB works with just numbers"column1": [1.2, 1.2, 1.2],"column2": ["a", "bb", "c"],"column3": ["K", "L", "M"]})df.to_sql("python", conn, if_exists="replace", index=True)conn.commit()conn.close()

any help will be really appreciated. many thanks.


Viewing all articles
Browse latest Browse all 17041

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>