Featuretools从多个列创建索引 [英] Featuretools create index from multiple columns

查看:120
本文介绍了Featuretools从多个列创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用featuretools中的entity_from_dataframe函数从数据框创建实体.如果索引包含多个列,是否可以定义索引.我不确定是否需要列表,元组或其他数据结构.这是代码:

I am trying to create an entity from a dataframe using the entity_from_dataframe function in featuretools. Is there a way to define the index if it comprises of more than one column. I'm unsure if I need a list, tuple or some other data structure. This is the code:

es=es.entity_from_dataframe(entity_id="credit",
                       dataframe=credit_df,
                       index=["ID1","ID2"]
                       )

它会产生以下有关哈希性的错误

It generates the following error regarding hashability

TypeError:不可散列的类型:列表"

TypeError: unhashable type: 'list'

推荐答案

您只能将一个变量作为索引.在您的情况下,您应该在数据框中创建一个新列,该列是您要使用的两列的串联

You can only have a single variable be your index. In your case, you should create a new column in your dataframe that is the concatenation of the two columns you want to use

df["index"] = df["ID1"].astype(str) + "_" + df["ID2"].astype(str)

然后,您可以在创建实体时使用index作为索引.

Then, you can use index as the index when creating the entity.

这篇关于Featuretools从多个列创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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