首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法添加关系,因为dtype在Featuretools中不匹配

无法添加关系,因为dtype在Featuretools中不匹配
EN

Stack Overflow用户
提问于 2018-09-25 19:31:21
回答 1查看 324关注 0票数 0

当试图在Featuretools中添加两个实体之间的关系时,会出现以下错误

代码语言:javascript
复制
Unable to add relationship because ID in metadata is Pandas `dtype category` and ID in transactions is Pandas `dtype category`

注意,该系列不一定是相同的cat.Codes

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-25 19:35:03

出现此错误是因为您试图关联的分类变量之间的类别不同。在下面的代码示例中,所有3个系列都是分类的,但只有ss2具有相同的dtype。

代码语言:javascript
复制
import pandas as pd
from pandas.api.types import is_dtype_equal

s = pd.Series(["a","b","a"], dtype="category")
s2 = pd.Series(["b","b","a"], dtype="category")
s3 = pd.Series(["a","b","c"], dtype="category")

is_dtype_equal(s.dtype, s2.dtype) # this is True
is_dtype_equal(s.dtype, s3.dtype) # this is False

要解决这个问题,您需要在将数据加载到Featuretools之前更新数据,以确保Pandas分类具有相同的值类别值。你是怎么做到的

如果s缺少s3中的类别

代码语言:javascript
复制
new_s = s.astype(s3.dtype)
is_dtype_equal(new_s.dtype, s3.dtype) # this is True

如果两个系列都缺少了另一个类别,我们必须将这些类别结合起来

代码语言:javascript
复制
s4 = pd.Series(["b","c"], dtype="category")

categories = set(s.dtype.categories + s4.dtype.categories) # make union of categories

new_s = s.astype("category", categories=categories)
new_s4 = s4.astype("category", categories=categories)

is_dtype_equal(new_s.dtype, new_s4.dtype) # this is True
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52505484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档