假设我有这个简单的代码片段。我将对数据帧进行分组、聚合和合并:
df = pd.DataFrame({'A': [1, 1, 2, 2],
'B': [1, 2, 3, 4],
'C': [0.3, 0.2, 1.2, -0.5]})
数据框:
^{pr2}$
groupby_A(min_B) groupby_A(min_C)
A
1 1 0.2
2 3 -0.5
df_new = pd.merge(df,df_result,on='A')
df_new
新东方:
A B C groupby_A(min_B) groupby_A(min_C)
0 1 1 0.3 1 0.2
1 1 2 0.2 1 0.2
2 2 3 1.2 3 -0.5
3 2 4 -0.5 3 -0.5
# ---- Import the Module ----
import featuretools as ft
# ---- Make the Entity Set (the set of all tables) ----
es = ft.EntitySet()
# ---- Make the Entity (the table) ----
es.entity_from_dataframe(entity_id = 'df',
dataframe = df)
# ---- Do the Deep Feature Synthesis (group, aggregate, and merge the features) ----
feature_matrix, feature_names = ft.dfs(entityset = es,
target_entity = 'df',
trans_primitives = ['cum_min'])
feature_matrix
特征矩阵:
A B C CUM_MIN(A) CUM_MIN(B) CUM_MIN(C)
index
0 1 1 0.3 1 1 0.3
1 1 2 0.2 1 1 0.2
2 2 3 1.2 1 1 0.2
3 2 4 -0.5 1 1 -0.5
使用Pandas的操作如何转化为featuretools(最好不添加另一个表)?在
我对featuretools的尝试没有给出正确的输出,但是我相信我使用的过程在某种程度上是正确的。在
下面是在Featuretools中推荐的方法。您确实需要创建另一个表以使其完全按照您的需要工作。在
这就回来了
^{pr2}$如果不想创建额外的表,可以尝试使用
cum_min
原语,该原语按A
分组后计算累计值这就回来了
相关问题 更多 >
编程相关推荐