Reputation: 898
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 .
Upvotes: 3
Views: 9369
Reputation:
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)
Upvotes: 3