如果表中没有可以用作唯一索引的列,可以让featuretools自动创建一个。打电话的时候
EntitySet.entity_from_dataframe(...)
index
参数和设置
make_index=True
例如,在下面的代码中
event_id
索引将自动创建
import pandas as pd
import featuretools as ft
df = pd.DataFrame({"customer_id": [0, 1, 0, 1, 1],
"date": [pd.Timestamp("1/1/2018"), pd.Timestamp("1/1/2018"),
pd.Timestamp("1/1/2018"), pd.Timestamp("1/2/2018"),
pd.Timestamp("1/2/2018")],
"event_type": ["view", "purchase", "view", "cancel", "purchase"]})
es = ft.EntitySet(id="customer_events")
es.entity_from_dataframe(entity_id="events",
dataframe=df,
index="event_id",
make_index=True,
time_index="date")
print(es["events"])
在events实体中,您可以看到event\ id现在是一个变量,即使它不在原始数据帧中
Entity: events
Variables:
event_id (dtype: index)
date (dtype: datetime_time_index)
customer_id (dtype: numeric)
event_type (dtype: categorical)
Shape:
(Rows: 5, Columns: 4)