Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Load Oracle table directly from Pandas (write to Oracle)

Is there any way to load data directly into an Oracle table from Pandas.

Currently I'm writing the data set into a csv file and then loading the table. I would like to bypass "writing to csv" step.

I'm using cx_Oracle for connecting to Oracle database. url is passed as a parameter when calling the python script. result will be stored as a pandas dataframe in variable dataset . The layout of dataset and table definition are same.

    import cx_Oracle as cx
    response = requests.get(url)
    data = response.json()
    dataset = json_normalize(data['results'])

Please let me know if you require any further .

like image 200
Leo Avatar asked Dec 20 '25 09:12

Leo


1 Answers

Did you try to_sql function from pandas module?

from sqlalchemy import create_engine
engine = create_engine('oracle://[user]:[pass]@[host]:[port]/[schema]', echo=False)
dataset.to_sql(name='target_table',con=engine ,if_exists = 'append', index=False)

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!