2

如何获取功能工具中的列名列表。

在熊猫数据框中,我只需键入此代码

dataframe.columns

返回列名列表

但是,我尝试在实体集中执行此操作但失败了。我应该将实体集转换为数据框吗?

我现在通过将变量转换为字符串并执行正则表达式来获取变量的名称来做到这一点。但是,我相信有更好的方法来做到这一点。

谢谢你,

4

1 回答 1

2

一个实体集包含多个数据框,每个实体都有。

In [1]: import featuretools as ft

In [2]: es = ft.demo.load_retail()

In [3]: es
Out[3]: 
Entityset: demo_retail_data
  Entities:
    order_products [Rows: 401604, Columns: 7]
    customers [Rows: 4372, Columns: 2]
    products [Rows: 3684, Columns: 3]
    orders [Rows: 22190, Columns: 5]
  Relationships:
    order_products.product_id -> products.product_id
    order_products.order_id -> orders.order_id
    orders.customer_name -> customers.customer_name

如果您希望“订单”实体的变量运行

In [4]: es["orders"].variables
Out[4]: 
[<Variable: order_id (dtype = index)>,
 <Variable: country (dtype = categorical)>,
 <Variable: cancelled (dtype = boolean)>,
 <Variable: first_order_products_time (dtype: datetime_time_index, format: None)>,
 <Variable: customer_name (dtype = id)>]

如果你想访问底层数据框本身运行

In [5]: es["orders"].df.head(5)
Out[5]: 
       order_id         country  cancelled first_order_products_time  customer_name
536365   536365  United Kingdom      False       2010-12-01 08:26:00   Andrea Brown
536366   536366  United Kingdom      False       2010-12-01 08:28:00   Andrea Brown
536367   536367  United Kingdom      False       2010-12-01 08:34:00  Krista Maddox
536368   536368  United Kingdom      False       2010-12-01 08:34:00  Krista Maddox
536369   536369  United Kingdom      False       2010-12-01 08:35:00  Krista Maddox
于 2018-09-18T15:49:46.497 回答