python - 数据类型映射参数中的键只能使用列名

标签 python pandas dask

我已成功使用 dask read_sql_table 从 Oracle 数据库引入一张表。但是,当我尝试引入另一个表时,我收到此错误 KeyError: '只有列名可以用作 dtype 映射参数中的键。'

我已经检查了我的连接字符串和架构,所有这些都很好。我知道表名存在,并且我尝试用作索引的列是 Oracle 数据库中表的主键。

有人可以解释为什么当列名明确存在时会出现此错误吗?

我知道我可以使用 Pandas block ,但在这种情况下宁愿使用 dask。

下面是我如何连接到 oracle 数据库以及错误消息的最后一点

host='*******'
port='*****'
sid='****'
user='******'
password='*****'

con_string = 'oracle://' + user + ':' + password + '@' + host + ':' + port + '/' + sid 
engine = create_engine(con_string)

df =ddf.read_sql_table('table_name', uri=con_string, index_col='id', npartitions=None, schema='*****')

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in astype(self, dtype, copy, errors, **kwargs) 5855
if col_name not in self: 5856 raise KeyError( -> 5857 "Only a column name can be used for the " 5858 "key in a dtype mappings argument." 5859 )

KeyError: 'Only a column name can be used for the key in a dtype mappings argument.'

今天,对于另一个表,我在 ddf.read_sql_table 中添加了所有列名,并且查询有效。但对于另一个表,我尝试通过列出所有列名来执行相同的操作,但我得到了上面的 KeyError 。

谢谢大家。

最佳答案

当列名称不匹配或数据类型映射中存在表中不存在的列时,通常会发生此错误。

关于python - 数据类型映射参数中的键只能使用列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58795861/

相关文章:

python - 我的 numpy 数组总是以零结尾?

Python 请求不适用于 https 代理

python - 如何在 Pandas 中的 groupby 中进行滚动窗口聚合?

sqlalchemy - 在 SQLAlchemy 中正确处理 Dask 多处理

python - dask client.submit 的行为

python - 在 Qt 中启动单独的进程

python - Pyexcel 保存到字典吗?

python - 用于 bool 索引的 Pandas、loc 与非 loc

python - 使用python创建多列的虚拟变量

python - Python函数的Dask Apply