Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Pandas Write_Frame to export results to Oracle Database in cx_Oracle

I am trying to export a Pandas DataFrame to an Oracle database. I have come across the Write_Frame function in Pandas which sounds like exactly what I need.

However, I have done tons of searches online and just can't get it to work. I have imported cx_Oracle and can connect to the Oracle database as well as running SQL queries without any problems, but when I run this it gives me a 'NotImplementedError':

import pandas.io.sql as psql

 output = psql.write_frame(MyResults, name = 'MySchema.MyTable', con = MyCon, 
                           flavor = 'oracle', if_exists = 'replace')

So far I have seen many examples of wrtie_frame on sqlite and mysql, so does that mean it won't work if flavor = 'oracle'? I have tried changing the flavor to mysql but it gives me an error saying 'Invalid SQL statement'??

Could anyone help me fixing this as I prefer not having to write the results to a CSV file then export to the database table?

Thanks

like image 659
user3311225 Avatar asked Mar 17 '14 16:03

user3311225


1 Answers

To expand on Andy Hayden's comment: oracle is indeed not supported in pandas <= 0.13 and older (only sqlite and mysql were supported).

But the sql module got a big overhaul in 0.14 (in development at the moment). It now uses sqlalchemy under the hood, so normally oracle should now be supported through sqlalchemy. See the dev docs for more details: http://pandas-docs.github.io/pandas-docs-travis/io.html#io-sql. And indeed, if you would be able to test it with oracle and give some feedback, that would be fantastic!

like image 119
joris Avatar answered Sep 25 '22 22:09

joris