我有一个CSV数据集,如下所示:
Access_name,AppName,identityName
AC1,AP1,ID1
AC1,AP1,ID2
AC2,AP1,ID1
AC2,AP1,ID2
AC2,AP1,ID3
AC3,AP2,ID2
AC3,AP2,ID3
AC4,AP1,ID1
我想找到所有身份分配给的所有访问组合。你知道吗
例如:
AC1 - assigned to ID1, ID2
AC2 - assigned to ID1, ID2
AC3 - assigned to ID2, ID3
AC4 - assigned to ID1
AC1 and AC2 - assigned to ID1 and ID2.
AC1 and AC3 - assigned to - ID2
AC1 and AC4 - assigned to None
AC1 and AC2 and AC3 - assigned to ID2
AC1 and AC2 and AC4 - assigned to ID1
AC1 and AC3 and AC4 - assigned to None
AC2 and AC3 and AC4 - assigned to None
所有可能的组合都是如此。有效获取这些数据的最佳方法是什么。任何代码样本都将不胜感激。你知道吗
你可以通过定义一个函数来实现。要么使用itertools迭代
Access_name
中所有值的组合,要么尽早切断缺少的组合。第二种方法的优点是速度更快(特别是如果您的数据集很大—有许多不同的Access_name
值),但它不会生成None
行。你知道吗看起来是这样的:
要应用它,只需像这样预聚合数据帧:
然后使用以下方法得到结果:
输出如下所示:
使用以下输入数据:
相关问题 更多 >
编程相关推荐