Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Pandas将SQL写入Oracle时出错:类型错误:应为字符串、unicode或缓冲区对象_Python_Oracle_Pandas - Fatal编程技术网

Python 使用Pandas将SQL写入Oracle时出错:类型错误:应为字符串、unicode或缓冲区对象

Python 使用Pandas将SQL写入Oracle时出错:类型错误:应为字符串、unicode或缓冲区对象,python,oracle,pandas,Python,Oracle,Pandas,使用Pandas将SQL写入Oracle时出错:类型错误:尝试使用时需要字符串、unicode或缓冲区对象: 熊猫V0.15.2 SqlAlchemy V0.9.8 merged.to_sql('name_of_table', ora, schema='schema', if_exists='append', index=False) 这是我的引擎创建字符串: ora = create_engine('oracle://name:pass@site.domain.com:1521/instan

使用Pandas将SQL写入Oracle时出错:类型错误:尝试使用时需要字符串、unicode或缓冲区对象:

熊猫V0.15.2

SqlAlchemy V0.9.8

merged.to_sql('name_of_table', ora, schema='schema', if_exists='append', index=False)
这是我的引擎创建字符串:

ora = create_engine('oracle://name:pass@site.domain.com:1521/instance')
我以前有过,有过一个问题,但在Joris的帮助下解决了。更正后,它工作一次,然后开始提示上述错误

我试过了,但没有用

以下是全部错误:

merged.to_sql('name_of_table', ora, schema='schema', if_exists='append', index=False)Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 966, in to_sql
dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/sql.py", line 538, in to_sql
chunksize=chunksize, dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/sql.py", line 1172, in to_sql
table.insert(chunksize)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/sql.py", line 717, in insert
self._execute_insert(conn, keys, chunk_iter)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/sql.py", line 692, in _execute_insert
conn.execute(self.insert_statement(), data)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 729, in execute
return meth(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1162, in _handle_dbapi_exception
util.reraise(*exc_info)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 928, in _execute_context
context)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/dialects/oracle/cx_oracle.py", line 941, in do_executemany
cursor.executemany(statement, parameters)
TypeError: expecting string, unicode or buffer object
然后它会更进一步,但会弹出一个新的错误: sqlalchemy.exc.DatabaseError:(DatabaseError)ORA-00932:不一致的数据类型:预期的CLOB数


感谢您的帮助。谢谢

回答我自己的问题,尽管有点晚了。这围绕着数据库和数据帧之间的数据类型问题展开。将数据帧解析为与表相似的数据类型可以使其成功写入


再次感谢@Joris

能否显示
merged.info()
merged1.info()
的输出。此外,您是否有NaN值?如果只尝试将数据帧的第一行(
merged.head())附加到_sql(…)
)中,是否会遇到同样的问题?您也可以尝试将
echo=True
传递到
create\u engine
,以获得更详细的输出,了解正在发生的事情。@Joris,很抱歉,这方面的长期延迟,但我已经解决了。我马上会在这里发布我自己问题的答案。当然会发布你自己的答案,我对解决方案感兴趣!
merged.to_csv('name.csv', sep=',', index=False, dtype=object)
merged1 = pd.read_csv('name.csv', dtype=object)