如何使用 pandas Write_Frame将结果导出到cx_Oracle中的Oracle数据库 [英] How to use Pandas Write_Frame to export results to Oracle Database in cx_Oracle

查看:85
本文介绍了如何使用 pandas Write_Frame将结果导出到cx_Oracle中的Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Pandas DataFrame导出到Oracle数据库.我在Pandas中遇到过Write_Frame函数,这听起来确实正是我所需要的.

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.

但是,我已经在线进行了大量搜索,但无法使其正常工作.我已经导入了cx_Oracle,并且可以连接到Oracle数据库以及运行SQL查询而没有任何问题,但是当我运行它时,它给了我一个' NotImplementedError ':

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')

到目前为止,我已经在sqlite和mysql上看到了很多wrtie_frame的示例,这是否意味着如果flavor ='oracle',它将无法正常工作?我尝试将样式更改为mysql,但它给我一个错误,提示'无效的SQL语句' ??

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'??

有人愿意帮我解决这个问题,因为我更喜欢不必将结果写入CSV文件然后导出到数据库表吗?

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?

谢谢

推荐答案

在Andy Hayden的评论中进行扩展:pandas< = 0.13和更早的版本中确实不支持oracle(仅支持sqlite和mysql).

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

但是sql模块在0.14中进行了大修(目前正在开发中).现在它在后台使用sqlalchemy,因此通常现在应该通过sqlalchemy支持oracle.有关更多详细信息,请参见开发文档: http://pandas -docs.github.io/pandas-docs-travis/io.html#io-sql .确实,如果您能够使用oracle进行测试并提供一些反馈,那就太好了!

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!

这篇关于如何使用 pandas Write_Frame将结果导出到cx_Oracle中的Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆