我有一个df
我必须找到组的所有组合(比如说2对),然后必须跨唯一ID对它们进行分组
输出:
目前我找到了一种生成所有组合的方法,但似乎无法按唯一ID进行分组
我也提到了以下链接: Pandas find all combinations of rows under a budget
生成对的代码:
from itertools import combinations
li_4 =[]
for index in list(combinations(df.group.unique(),2)):
li_4.append([index[0],index[1]])
我们可以执行
merge
然后np.sort
并在用drop_duplicates
删除重复项后将结果传递给crosstab
相关问题 更多 >
编程相关推荐