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

泪湿孤枕 提交于 2019-12-12 08:42:54

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/22460515/how-to-use-pandas-write-frame-to-export-results-to-oracle-database-in-cx-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!