【发布时间】:2019-12-30 14:11:17
【问题描述】:
我正在尝试基于两个数据框中相同的 2 列创建实体关系,但我收到标题中所述的错误。
在互联网上搜索了该问题,但找不到任何东西
es = es.entity_from_dataframe(entity_id="train",
dataframe=df_es_train,
index="impression_id",
time_index="impression_time",
)
es = es.entity_from_dataframe(entity_id="viewlogs",
dataframe=df_es_view_logs,
index="index",
time_index="server_time",
)
es = es.entity_from_dataframe(entity_id="itemdata",
dataframe=df_es_item_data,
index="item_id",
)
new_relationship_1 = ft.Relationship(es["itemdata"]["item_id"],
es["viewlogs"]["item_id"])
es = es.add_relationship(new_relationship_1)
new_relationship = ft.Relationship(es["train"]["user_id"],
es["viewlogs"]["user_id"])
es = es.add_relationship(new_relationship)
实际结果是下面的错误,而这应该可以正常工作。
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-43-62d742a93d26> in <module>
21 es = es.add_relationship(new_relationship_1)
22 new_relationship = ft.Relationship(es["train"]["user_id"],
---> 23 es["viewlogs"]["user_id"])
24 es = es.add_relationship(new_relationship)
D:\Anaconda3\envs\fastai\lib\site-packages\featuretools\entityset\relationship.py in __init__(self, parent_variable, child_variable)
25 if (parent_variable.entity.index is not None and
26 parent_variable.id != parent_variable.entity.index):
---> 27 raise AttributeError("Parent variable '%s' is not the index of entity %s" % (parent_variable, parent_variable.entity))
28
29 @classmethod
AttributeError: Parent variable '<Variable: user_id (dtype = numeric)>' is not the index of entity Entity: train
Variables:
impression_id (dtype: index)
impression_time (dtype: datetime_time_index)
user_id (dtype: numeric)
app_code (dtype: numeric)
os_version (dtype: numeric)
is_4G (dtype: numeric)
形状: (行:237609,列:6)
【问题讨论】:
-
错误是说
user_id不是实体的主键。 FT 中的关系是一对多的,这就是为什么user_id必须是主键
标签: python-3.x entity-relationship featuretools